• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » JSP » Java Server Pages

JSTL Core fmt:parseNumber Tag

By Dinesh Thakur

This tag is Used to represent number as parsing Type like to display the number with decimal value or with only Integer type. As shown in the example below some attributes like value and var used to implement in that program. Var attribute use to store the variable value. Value will be use to assign the type of number.

<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %>

<%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt” %>

<html>

   <head>

          <title>JSTL Example of&lt;fmt:parseNumber&gt; Tag</title>

   </head>

       <body>

               <center><br><h3>Demo Of Number Parsing In JSTL:</h3></br></center>

                         <c:set var=”amt” value=”2370000.9866″ />

                               <fmt:parseNumber var=”bal” type=”number” value=”${amt}” />

               <b><center><p>Number Parsed (1) : <c:out value=”${bal}” /></p></center></b>

                               <fmt:parseNumber var=”bal” integerOnly=”true”

                                    type=”number” value=”${amt}” />

               <b><center><p>Number Parsed (2) : <c:out value=”${bal}” /></p>

       </body>

</html>

      JSTL Tag <fmt:ParsedNumber>

This Program is an example to represent the <fmt: ParsedNumber> tag. In this program we first use the JSTL tag Library to access the library as requirement. After that we declare the Variables which use to contain the stored value in the body section we use the JSTL tag with HTML code tags that will use to bring the output on the web browser. In the last we close all body parts of program(HTML).  

JSTL Core fmt:formatDate Tag

By Dinesh Thakur

This tag is Just Use to Display The Date and time In unique formats like in long style, Medium style. The style to represent date in “yyyy-dd-mm” format. As per other tags the required attributes are also used in this tag.

<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %>

<%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt” %>

<html>

       <head>

           <title>JSTL &lt;fmt:dateNumber&gt; Tag</title>

       </head>

       <body>

              <b><center><h3>Date Format in JSTL</h3></b></center>

                   <c:set var=”dt” value=”<%=new java.util.Date()%>” />

              <b><center><p>Date as Formated(1): <fmt:formatDate type=”time”

                                                                       value=”${dt}” /></p></center></b>

              <b><center><p>Date as Formated(2): <fmt:formatDate type=”date”

                                                                       value=”${dt}” /></p></center></b>

              <b><center><p>Date as Formated (3): <fmt:formatDate type=”both”

                                                                      value=”${dt}” /></p></center></b>

              <b><center><p>Date as Formated (4): <fmt:formatDate type=”both”

                                                                        dateStyle=”long” timeStyle=”long”

                                                                      value=”${dt}” /></p></center></b>

             <b><center><p>Date as Formated (5): <fmt:formatDate pattern=”yyyy-MM-dd”

                                                                      value=”${dt}” /></p></center></b>

       </body>

</html>

       JSTL Tag <fmt:formatDate>

This program is just as a demo of that how to display the system date & time in unique formats as required first we call the JSTL tag library codes. That will help to access the required functions. Then after declaring mandatory variables and tags that been use to represent output on web browser the java utility package also been called while output criteria as for display on browser. Here after every command we use the condition that how the date and time will display like medium, long or in pattern way.

JSTL Core fmt:setTimeZone Tag

By Dinesh Thakur

This tag <fmt: setTimeZone> Is used to set the required Time Zone Into its Scoped variable, Which can access from it’s Body. Some Attributes also been used like var, value and scope.

 

The mandatory attribute in this tag is Value that will used to display the time zone as scope variable. The other will use to as optional part as their requirements.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<%@ taglib uri=”http://java.sun.com/jsp/jstl/fmt” prefix=”fmt” %>

<html>

<head>

       <title>&lt;fmt:setTimeZone&gt; Tag In JSTL</title>

</head>

    <body>

             <c:set var=”nw” value=”<%=new java.util.Date()%>” />

             <br><p><b><center>Date in Current Zone:

                   <fmt:formatDate value=”${nw}” type=”both”/></p></center></b>

             <p><b><center>Change Time Zone to GMT-6.30</p></center></b>

                  <fmt:setTimeZone value=”GMT -6.30″ />

            <p><b><center>Changed Time Zone Date & Time:

                 <fmt:formatDate value=”${nw}” type=”both”/></p></center></b></br>

    </body>

</html>

      JSTL Tag <fmt:setTimeZone>

In this program we just describe that how to set the time zone from current time zone Pattern First we use the JSTL Tag Lib. Then after using required attribute with the code of HTML. To represent the Time of System we call the Java Utility package for time and date in the Program. Then we use as usual required tags for complete coding.

JSTL Core fmt formatNumber Tag

By Dinesh Thakur

In JSTL the tag <fmt: format Number> is been preferred for the showing Number formation In different Format. There are some attributes are used in the tag for proper display.

 

Like Value, type, Pattern, var etc. in Value attribute the required value is been filled as per recommendation the other one we use Type this attribute used to specify that which kind of value will be formatted will it be Number, Currency or Percentage. And in Last we has to use Pattern and var the var attribute used to give a variable name that store the value to be formatted.

<%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt” %>

<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %>

<html>

     <head>

               <title>&lt;fmt:formatNumber&gt;Tag Example In J.S.P</title>

    </head>

       <body>

                 <center><h2>Demo Of Number Format</h2></center>

                <c:set var=”format” value=”3400086.789″/>

                <p><center><b>Formatted Number (1): <fmt:formatNumber value=”${format}”

                          type=”currency”/></p></b></center>

                <p><center><b>Formatted Number (2): <fmt:formatNumber type=”number”

                          maxIntegerDigits=”2″ value=”${format}” /></p></b></center>

                <p><center><b>Formatted Number (3): <fmt:formatNumber type=”number”

                          groupingUsed=”true” value=”${format}” /></p></b></center>

                <p><b><center>Formatted Number (4): <fmt:formatNumber type=”percent”

                          maxIntegerDigits=”3″ value=”${format}” /></p></center></b>

                 <p><b><center>Formatted Number (5): <fmt:formatNumber type=”number”

                          pattern=”###.###E0″ value=”${format}” /></p></center></b>

                <p><center><b>Currency in USA :

                       <fmt:setLocale value=”en_US”/>

                       <fmt:formatNumber value=”${format}” type=”currency”/>

               </p></b>

       </body>

</html>

      JSTL Tag <fmt:format Number>

Here We made a program of <fmt: format Number> first we call the JSTL Library Code in the starting Of program and after then declaring a variable and assures the value we use some required attributes in given codes that will bring the Output as per their phase. Like we use grouping, Decimal place formatting like pattern and currency Mode also. And in the last we closed all the Html tags.

What is the difference between PrintWriter and JspWriter?

By Dinesh Thakur


PrintWriter

JspWriter

Does not support buffering

supports buffering

Does not use BufferWriter internally

Uses BufferWriter, PrintWriter internally  

Can create class of java.io.* package

Abstract class of javax.servlet.jsp package

Its print (-) method does not throw IOException

Its print (-) method throw

IOException

Useful for servlet programming

It is the type of implicit object out in JSP

Why is it optional to configure web.xml file in case of JSP as it is mandatory for servlet program?

By Dinesh Thakur

We know servlet program is placed in WEB-INF folder. WEB-INF is a private directory of deployed web application. So any web resource program that is placed in WEB-INF folder or its subfolder (like classes) must be configured in web.xml file to make the underlying container and server recognizing web resource program.

 

Exploring Implicit Objects

By Dinesh Thakur

A JSP program can have two types of objects.

• Explicit objects

• Implicit objects [Read more…] about Exploring Implicit Objects

Commenting Code in JSP

By Dinesh Thakur

JSP comment

Used for commenting JSP tags base code (or JSP code) of JSP program. A JSP page compiler recognizes JSP comments. As JSP comments are visible in source, code of  JSP program and not visible in any other process of JSP program execution so these are called hidden comments. They are written like this:

<%–……..–>

HTML Comments

Used for commenting html code and text of JSP program. Html interceptor recognizes this type of comments. We use html comment on scripting JSP tags (scriptlet, declaration and expression) but we cannot use these comments on other JSP tags. They are written like this:

<!– ……………..–>Script comments

Java compiler recognizes this type of comments.

//:-used for commenting one line of code

/*….* /: -used for commenting multiple line of code

                                        Visibility Chart of JSP Comments

Comments

In JSP

program

Source code of java equivalent Servlet

Compiled of java equivalent Servlet

Html code that comes to browser

Output

JSP comments

Yes

–

–

–

–

Html

Yes

Yes

Yes

Yes

–

Java comments

Yes

Yes

–

–

–

 

JSP Scripting Elements

By Dinesh Thakur

A JSP page contains tags. The tags are in the form of scripting tags, directive tags and comments. Tags help programmers to develop Java codeless JSP program. Implicit objects increase the functionality of JSP page. Scripting element also helps in generating dynamic content and displaying dynamic content. [Read more…] about JSP Scripting Elements

Life Cycle of JSP

By Dinesh Thakur

Life cycle of a program includes the phases starting from creating objects for the class, execution, and at last destruction of objects. For this life cycle, JSP needs some life cycle methods.

The method that is called by container automatically and directly when event is raised is called life cycle method. The methods which are called internally from this life cycle methods are called life cycle convince helper methods.

Life cycle of JSP is similar to Servlet life cycle.

In the execution phase of JSP page, first JSP page is translated into an equivalent Servlet, then the source file of the Servlet is compiled into a .class file. Every time a JSP page is requested, its corresponding Servlet will be executed. So life cycle of JSP is similar to Servlet life cycle.

JSP Life-Cycle Methods

The methods called by the container automatically when event is raised are called life-cycle methods.

As you know, JSP page is first converted into an equivalent Servlet program, so life cycle method of JSP is same as Servlet life-cycle method. But Sun Microsystems has given three life-cycle convince methods as alternatives to original life-cycle methods.

Like:

for init(-) _jspInit()

service(-,-)….._jspService(-,-)

destroy () ……._jspDestroy ()

init(-) method internally calls the convince method _jsplnit() from super class of JSP equivalent servlet class.

service(-,-) internally calls the convince method _jspService(-,-) from super class of JSP equivalent servlet class.

destroy() internally calls the convince method _jspDestroy() from super class of JSP equivalent servlet class.

The super class for JSP equivalent Servlet is server dependent. In Tomcat server, the super class is org.apache.jasper.runtime.Http]spBase. Every JSP equivalent Servlet is HttpServlet by default.

Main Stages of The Life-Cycle Of A JSP Page

• JSP Page compilation

• Source Code Compilation

• Life Cycle ConvinceMethodExecution

JSP Page Compilation

Page compilation: The process of converting JSP code into an equivalent Servlet program code is called JSP page compilation.

In this phase, web container translates the JSP page into an equivalent Servlet code. The main objective of page translation is to convert the tag based code into more Java code for smooth execution by the JVM. The translation of JSP is automatically done by the server at the time of deploying web application or JSP receives the request for the first time.

In this phase, web container performs the activity like locating requested JSP page, validating the syntactic correctness of the JSP pages, and generating source code of equivalent Servlet code for JSP page.

i. Source code compilation:

In this stage, JSP container compiles the Java source code i.e. the equivalent servlet code and converts into Java byte (.class) code. Generally, most servers like web logic, discard the generated source code after compilation phase.

ii. Life cycle convinces methods execution:

Initialization: After the compilation phase, web container loads the class file. To create instance of Servlet class, ISP container uses the no-argument constructor. After that the container initializes the objects by invoking the init(ServletConfig) method. This method is called jsplnit() method.

Request processing: In this stage, web container uses the successfully initialized ISP equivalent Servlet objects to process client request. As per Servlet life cycle web container invokes service(-,-) method on the Servlet object by passing the request object of HttpServletRequest and response object of HttpServletResponse. In case of JSP equivalent Servlet. the container invokes the _jspService() method.

Destroying: If Servlet container wants to destroy the instances then it performs the following activities-First it allows time to currently executing threads to complete their operations and simultaneously it makes Servlet instance unavailable for other requests. After the current threads complete their operations on service( -,-) method, then the container calls the destroy() method on a Servlet instance, which invokes the jspDestroy() method.

Creating a Simple JSP Page

Here we are creating a simple web application which will show current system date and addition of numbers. Till know we have not discussed the various tags like scriptlets, directives. So this will give you an idea about how ISP program is designed, used, deployed in server, and accessed through browser windows.

Procedure to Develop and Deploy JSP-based Web Application

Settings needed: A web server or application server (here we have taken Tomcat

server)

Jar file to be set in the CLASSPATH: Servlet-api.jar or jsp-api.jar file have to be set to the CLASSPATH.

To set jar file to CLASSPATH: Copy the path of the jar file from the address bar of folder where Tomcat is installed as shown:

F:\ Tomcat 6.0\lib \servlet-apLjar

then

Right click on my computer

Click properties

Click advanced tab

Click environment variables

Click ‘new’ button of system variables and set

variable name: CLASSPATH

variable value: F:\ Tomcat 6.0\lib \servlet-api.jar; (paste and insert ‘;’ at the end) click OK for installation Tomcat server.

Development of Web Application

Step 1 Create a deployment directory structure like this

                          

Here WEB-INF, web.xml is case sensitive and .jsp file should be placed parallel to WEB-INF folder

Step 2 Welcome.jsp

<html>

<hl> <center> Welcome to JSP </center> </hl>

<b> <center> <font size=5>Systems date and time is :- </font> </center> </b>

<% java.util.Date d=new java.util.Date (); %>

<body> <font color=“red” size=6/> <center>

<%

out.println (d.toString ());

%>

</center>

</html>

Save this file as Welcome.jsp, the extension is .jsp

Step 3 Configuration of web.xml in JSP program is optional

You can make web.xml as

web.xml

<web-app/>

Deploy the web application

Step 4 Start the Tomcat server

Click F:\Tomcat 6.0\bin\tomcat6.exe file (or) Open command prompt and specify the path of bin folder of Tomcat and type as given below:

F:\Tomcat 6.0\bin>java -jar bootstrap.jar and press enter

Step5 Copy the JspApp folder and paste in F:\ Tomcat 6.0\ webapps folder

Step6 Testing of web application

Open browser window and write in the address bar of browser as follows:

https://ecomputernotes.com:8080/JspApp/Welcome.jsp

localhost: Because system is not in network, if system is in network then type IP address of the system in place of local host.

8080: It is the port number of Tomcat. You can give any 4-digit number at the time of Tomcat installation.

JspApp: is the JSP application folder name.

                    

After giving request to browser window, the JSP equivalent Servlet code (JES) and .class file will create in F:\Tomcat 6.0\work\catalina\localhost\jspApp\org\apache\jsp

And the JES code will like this…

 

package org.apache.jsp;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.servlet.jsp.*;

public final class Welcome_jspextends org.apache.jasper.runtime.HttpJsp

Base implements org.apache.jasper.runtime.JspSourceDependent

{

     private static final JspFactory_jspxFactory =

     JspFactory.getDefaultFactory();

     private static java.util.List_jspx_dependants;

     private javax.el.ExpressionFactory_el_expressionfactory;

     private org.apache.AnnotationProcessor_jsp_annotationprocessor;

     public object getDependants ()

     {

           return_jspx_dependants;

     }

      public void_jsplnit ()

      {

            _el_expressionfactory = _jspxFactory.getJspApplicationContext

            (getServletConfig ().getServletContext ()).getExpressionFactory ();

            _jsp_annotationprocessor = (org.apache.Annotationprocessor)

            getServletConfig ().getServletContext ().getAttribute

            (org.apache.Annotationprocessor.class.getName ());

      }

       public void_jspDestroy ()

       {

       }

       public void_jspService (HttpServletRequest request, HttpServlet

       Response response) throws java.io.IOExcption, Servletexception

       {

            PageContext pageContext = null;

            HttpSession session = null;

            ServletContext application = null;

            ServletConfig config = null”;

            JspWriter out= null;

            Object page= this;

            JspWriter_jspx_out = null;

            PageContext_jspx_page_context = null;

            try

           {

                response.setContentType (“text/html”);

                pageContext = _jspxFactory.getPageContext (this, request,

                response, null, true, 8192, true);

               _jspx-page_context = pageContext;

               application = pageContext.getServletContext ();

               config = pageContext.getServletConfig          ();

               session = pageContext.getSession ();

               out = pageContext.getOut ();

              _jspx_out = out;

              out.write (“<html>\r\n”);

              out.write (“<hl> <center> Welcome to JSP </center> </hl>\r\n”);

              out.write (“<b> <center> font size=5>Systems date and time is:-

              </font> </center> </b>\r\n”);

              java.util.Date d=new java.util.Date();

              out.write (“\r\n”) ;

              out.write (“<body> <font color=\“red\” size=6/> <center>\r\n”);

              out.println (d.toString ());

              out.write (“\r\n”);

              out.write(“</center>\r\n”) ;

              out.write(“</html>\r\n”) ;

           }

           catch (Throwable t)

          {

               if (! (t instanceof SkipPageException))

              {

                   out = _jspx_out;

                   if (out != null && out.getBufferSize () !=0)

                   try

                  {

                       out.clearBuffer ();

                  }

                  catch (java.io.IOException e)

                 {

                 }

                 if (_jspx-page_context != null)_jspx_page_context.handlePage

                 Exception (t);

              }

          }

          finally

         {

              _jspxFactory.releasePageContext (_jspx_page_context) ;

         }

      }

}

Here the point to consider is that the JES file name is Welcome_jsp.java and class name is Welcome_jsp.class and all implicit object is visible in _jspService (-,-) method. You can see the implicit objects are visible inside _jspService (-,-) method.

JSP Program Structure

By Dinesh Thakur

A JSP page mainly comprises the following types of code.

• HTML Code

HTML code is used for displaying the HTML output like text field, check box, option menu where user can give requested data to the web application and also for generating other static content of the web page. HTML codes can be embedded easily in the JSP page.

• Scripting Code

Scripting code means the codes which have nested in some other code without any extension. Like JavaScript code it is used in JSP page to get some more dynamism like email id validation, password field length validation, etc.

• Scripting Tags

Java codes are placed inside the scripting tags. There are three types of scripting tags in JSP: Scriptlet Tag, Declaration Tag, Expression Tag.

Template Text

Template text is a combination of normal text and HTML code. It is the uninterrupted data of a JSP page. It is guides the end user when entering data in the required fields.

                          JSP program structure

Architecture of JSP

By Dinesh Thakur

For web application development JSP generally supports two types of architecture.

i.  Model 1 and

ii. Model 2 architecture

JSP Model-I Architecture

In model 1 architecture, the web browser directly accesses the JSP pages. If there is need of, generating output from database jsp page interacts with JavaBeans, which is present inside the web container of model 1 architecture.

                 Architecture of JSP

JSP Model II Architecture

In model 2 architecture, the browser accesses the JSP page indirectly. The Servlet program acts as controller between JSP page and browser window. If JSP page needs to interact with database for response then servlet program creates the instances of JavaBeans, and JavaBeans invokes the database server.

                web server or application server

Features of JSP Programming.

By Dinesh Thakur

• Supports tags based programming

JSP supports tag-based programming. As it is a tag-based programming extensive knowledge of Java is not required. Non-Java users can learn it easily. This tag increases the readability of code. Gives built-in JSP tags and also allows to develop custom JSP tags and also to use third party supplied JSP tags.

• Implicit objects

JSP gives nine implicit objects. We can use them directly in our program without writing any additional code to access.

• Code separation

It allows separate presentation logic (html code) and business logic (java code). So does not look bulky. Here we do not have to put html code inside pw.printin() .

• Exception handling

Exception handling is optional in JSP. Container takes care of exception handling. And also implicit object exception is given to get the exception type, but it is only visible inside error page.

• Easy loading

After modifications we do not need to recompile and reload it. We just have to save it and then directly we can send request; and the modifications will be visible. JSP also contains many more features like Standard directives, Scripting elements, Tag extension mechanism, Template content.

What are Advantages of JSP?

By Dinesh Thakur

We know that Servlet is a server side technology, so why has Sun Microsystems given JSP?

Servlet is a Java code based programming. To know servlet, strong Java knowledge is required. However, while working with ASP.net, PHP like technologies we can go for tag-based programming which is easier. So in initial days programmer did not like Servlet. To attract non-java programmers like ASP.net programmers and PHP programmer Sun Microsystems has introduced a server side technology which is tag based all features of servlet.

JSP enables us to mix up static HTML with dynamically generated content of servlet. the Take example of an online-shopping website, its initial page is mostly same for all visitors, except small changes like welcome message “Hi Mr / Ms Xxx” for registered users. When we develop this by servlet then we have to develop this entire page by writing coding in the Servlet program. However, JSP makes separate parts for static content and dynamic content.

Advantage of JSP over Servlet

JSP

Servlet

Allows tag based programming. So extensive java knowledge is not required.

Does not allow tag based programming. So extensive java knowledge is required.

Suitable for both java and non java programmer.

Not suitable for non java programmer.

Use nine implicit objects, which we can use directly in our JSP program

Implicit objects are present but we can’t use them directly. We need write additional code to use

them.

Modification done in JSP program will be recognized by underlying server automatically without reloading of web application.

Here we need to compile and reload manually.

Takes care of exception handling.

Does not take care of exception handling. Programmers have to explicitly handle this .

Allows us to use separate presentation logic (html code) from Java code(business logic).

Does not allow.

Increases readability of code because of tags.

Readability of code is less

Gives built-in JSP tags and also allows to develop custom JSP tags and to use third party supplied tags.

Does not allow tag based programming.

Easy to learn and easy to apply.

Not easy compared to JSP.

Advantages over All Other Technologies

• Versus active server pages (ASP)

ASP is given by Microsoft. It is also a tag-based programming language. ASP code is not portable. However, JSP code is portable because it is written in Java (i.e., we can reuse the code in other operating systems and also in other web server). We can use Java for JSP, so we need not stick with a particular server product or IIS.

• Versus PHP

It is an HTML embedded scripting language and it is also open source software like Java. It is similar to JSP and ASP. It is not suitable for large scale application and banking applications where money transaction occurs because of security reasons. For PHP we have to learn one new language.

• Versus JavaScript

JavaScript is in no way related with Java programming. It is normally used to generate HTML dynamically on the client machine. JavaScript is not suitable for network programming and to access server-side resources. Java is more powerful, flexible, reliable and portable than PHP.

• Versus HTML

Regular HTML, that is static HTML, does not contain dynamic information. So it does not react to user input and is also not fit for accessing server side resources. JSP contains both static and non-static content. As static part, it contains HTML.

What are disadvantages of servlet?

By Dinesh Thakur

There are some problems with Servlet programming.

For non-java programmers Servlet is not suitable as they need to have extensive knowledge of Java Servlet. The presentation logic (HTML code) will be mixed up with Java code (pw.println()). Lots of coding is written inside pw.println() to write html code. Modification done in one code may affect another code. Writing HTML code in Servlet programming is a complex process and it makes Servlet looks bulky.

In Servlet programming implicit objects are there but we need to write some additional code to get them access. Modifications done in source code of servlet program will be effected only after recompilation and reloading of the web application in case of most of servers. Programmers should explicitly take care of exception handling. Servlet programming is not thread safe by default. So we need to write additional codes to make the Servlet program thread safe.

What is JSP?

By Dinesh Thakur

JSP technology is the Java Platform Technology (enterprise technology) for delivering dynamic content to web user (the person who is giving request from browser window) in a portable, secure and well-defined way. JSP has been built on top of the Servlet API and utilizes Servlet semantics. It uses HTML and XML templates and Java code to generate JSP page. JSP is secure, fast and independent of server platforms.

Although JSP technology is going to be a powerful successor to basic Servlets, there is a relation between JSP and Servlet. Servlets are powerful and sometimes they are a bit cumbersome when it comes to generating complex HTML. But JSP is handy with HTML and JavaScript. JSP is also powerful compared to other web technologies like PHP, ASP as it is developed as per Java specifications.

Most Servlets contain codes to handle application logic and to handle output formatting. This can make it difficult to separate and reuse portions of the code when a different output format is needed. For these reasons, web application developers turn towards JSP as their preferred servlet environment. It also contains many more features like platform independent, server independent.

Evolution of Web Applications

Over the past few years, web server applications have evolved from static to dynamic application. This evolution became necessary due to some deficiencies in earlier website design. For example, to put more business processes on the web, both in business-to-consumer (B2C) or business-to-business (B2B) markets, conventional website design technologies are not enough.

The main issues every developer faces while developing web applications are as follows:

1. Scalability – A successful web site will have more users and as the number of users increase, the web applications have to scale correspondingly.

2. Integration of data and business logic – The web is just another way to conduct business, and so it should be able to use the same middle-tier and data-access code.

3. Manageability – Websites just keep getting bigger and we need some viable mechanism to manage the ever-increasing content and its interaction with business systems.

4. Personalization – Adding a personal touch to the web page becomes an essential factor to retain customers. Knowing their preferences, allowing them to configure the information they view, remembering their past transactions or frequent search keywords are all important in providing feedback and interaction from what is otherwise a fairly one-sided conversation.

Apart from these general needs of a business-oriented website, the necessity for new technologies to create robust, dynamic and compact server-side web applications has been realized. The main characteristics of today’s dynamic web server applications are as follows:

• Serve HTML and XML, and stream data to the web client

• Separate presentation, logic and data

• Interface to databases, other Java application server middleware to provide transactional support

• Track client sessions

Now let us have a look on the role of Java technology and platform in this regard.

Java’s Role for Server Applications

Sun Microsystems, having consulted many expert partners from other IT related industries, has come out with a number of open APIs for the technologies and services on server side. This collection of APIs is named as Java 2 Enterprise Edition (J2EE). The J2EE specification provides a platform for enterprise applications, with full API support for enterprise code and guarantees of portability between server implementations. Also, it brings a clear division between code which deals with presentation, business logic and data.

The J2EE specification meets the needs of web applications because it provides the following:

• Rich interaction with a web server via servlets and built-in support for sessions available in both Servlets and EJBs.

• The use of EJBs to mirror the user interaction with data by providing automatic session and transaction support to EJBs operating in the EJBs server.

• Entity EJBs to represent data as an object and seamless integration with the Java data access APIs.

• Flexible template-based output using JSP and XML.

This family of APIs means that the final web page can be generated from a user input request, which was processed by a Servlet or JSP and a session EJB, which represents the user’s session with the server, using data extracted from a database and put into an entity EJE. Thus, the Java revolution of portable code and open APIs is married with an evolution in existing products such as database, application, mail and web servers. The wide availability of products to run Java applications on the server has made Java lucrative in a very competitive market. This makes server-side Java a very exciting area.

The Java Server Pages 1.2 specification provides web developers with a framework to build applications containing dynamic web content such as HTML, DHTML and XML. A JSP page is a text based document containing static HTML and dynamic actions which describe how to process a response to the client in a more powerful and flexible manner. Most of a JSP file is plain HTML but it also has, interspersed with it, special JSP tags.

There are many JSP tags such as:

• <%@page language=”java” %> – this is a JSP directive denoted by <%@,

• scrip lets indicated by <%..%> tags and

• <%@include file=”sample.html”%>- this directive includes the contents of the file sample.html in the response at that point.

To process JSP file, we need a JSP engine that can be connected with a web server or can be accommodated inside a web server. Firstly when a web browser seeks a JSP file through an URL from the web server, the web server recognizes the .jsp file extension in the URL requested by the browser and understands that the requested resource is a JavaServer Page. Then the web server passes the request to the JSP engine. The JSP page is then translated into a Java class, which is then compiled into a Servlet.

This translation and compilation phase occurs only when the JSP file is requested for the first time, or if it undergoes any changes to the extent of getting retranslated and recompiled. For each additional request of JSP page thereafter, the request directly goes to the Servlet byte code, which is already in memory. Thus when a request comes for a Servlet, an init() method is called when the Servlet is first loaded into the virtual machine, to perform any global initialization that every request of the Servlet will need. Then the individual machine requests are sent to a service() method, where the response is put together. The Servlet creates a new thread to run service() method for each request. The request from the browser is converted into a Java object that is used to send the response back to the browser. The Servlet code performs the operations specified by the JSP elements in the .jsp file.

TAG Based Programming 

Programming may be code based or tag based. Code-based programming is difficult to write and understand. However, tag-based program is easier and program length is less as compared to codes based programming. Tags reduce the development time and maintenance cost and increases the reusability of code.

 

We have some ideas on tag-based programming like HTML, JavaScript and CSS, etc. JSP is also totally tag based. JSP tags implement the functionality of tags into tag implementation classes. So to develop JSP page, large amount of Java code is not needed. So this helps the programmer to develop java codeless JSP program by which developing separate presentation logic and business logic has become easier.

JSTL Core c redirect Tag

By Dinesh Thakur

This tag <c: redirect> redirects or forward to other URL or alternative URL provided in the condition. It also supports <c: param> tag some attributes are also use to make it proper like “URL” Attribute this will use to redirect the browser to other web page.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

   <html>

          <head>

                 <title>&lt;c:redirect&gt;Tag Example In J.S.P</title>

          </head>

          <body>

                 <p><b><br><center>

                      <c:set var=”age” scope=”request” value=”18″/>

                           <c:if test=”${age>=18}”>

                                  <c:redirect url=”canvote.jsp”/>

                           </c:if>

                            <c:if test=”${age<18}”>

                                  <c:redirect url=”cantvote”/>

                           </c:if>

                                 </p></b></br></center> 

          </body>

   </html>

                       JSTL Core c redirect Tag

This Program will execute if the condition goes true it will redirect to another page that will show the message “You Can vote” otherwise will skip to other web page that will show “You can’t vote”.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

     <head>

                <title>Vote Eligible</title>

     </head>

            <body>

                   <p><center><br><b>

                          <c:out value=”You Can Vote…”/>

                   </b></br></center></p>

            </body>

</html>

False condition URL page will be redirect as below …

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

     <head>

               <title>Vote Eligible</title>

     </head>

           <body>

                       <p><center><br><b><c:out value=”You Can’t Vote…”/></b></br></center></p>

           </body>

</html>

JSTL Core c remove Tag

By Dinesh Thakur

This tag is used to remove the variable from specified place or with the reference of scope of the variable when the particular space is not set on the first instance for removing variable. This tag ensures that it will remove any scoped resource or variable it tells to remove. Some attributes it also required for it. Like “var” variable name that has to be removed with the help of this tag.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

     <html>

          <head>

                   <title>&lt;c:remove&gt;Tag Example In J.S.P</title>

          </head>

               <body>

                          <c:set var=”Book_Price” scope=”session” value=”${2500}”/>

                              <p><b><center><br>

                                       Before Removing Content The Price Of Book Is :<c:out value=”${Book_Price}”/>

                              </center></b></p></br>                

                                      <c:remove var=”Book_Price”/>

                             <p><b><center>

                                      After Removing Content The Price Of Book Is :<c:out value=”${Book_Price}”/>

                             </center></b></p>

               </body>

     </html>

                     JSTL Core c remove Tag

About Program….

This tag is been present as a form of example in the program we remove the value of book price as mentioned before removing and after removing. First instance we use to call the taglib (tag library) in JSTL. Then after initializing the tags of HTML we set the value in variable and variable name. after that prints a message that the book price before removing the content..And then make a use of remove tag after prints a message on web browser that after removing content from the variable. In the last all required tags are closed.

JSTL Core c set Tag

By Dinesh Thakur

This tag is commonly use for the set property action of any object like to set value, property name. Their also some attributes are used to this tag like “Value” that’s use to save the information. “var” the variable name that has to store the information about value. The other thing this tag is use to evaluates the expression.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

    <head>

            <title>&lt;c:set&gt;Tag Example In J.S.P</title>

   </head>

         <body>

                 <c:set var=”pay” scope=”session” value=”${2500*4}”/>

                <p><b><center><br>Your Pay is :<c:out value=”${pay}”/></center></b></p>

         </body>

</html>

                  JSTL Core c set Tag

About Program…..

As we mentioned earlier that the <c: set> tag is used to set the property and its uses to evaluate the expression. In the program to elaborate this tag we use to set the salary of an employee in that some attributes like var variable that will store the info about output. Scope that has to admire the scope of variable that will store information. In last instance the salary is to be deployed on the web browser.

JSTL Core c param Tag

By Dinesh Thakur

                   This tag is used to access proper URL request parameter which is been accessed with URL also.

 

Some Necessary attributes are also used to make this tag a manner thing for use like we use “NAME” attribute that is used to set the parameter request in URL. The other attribute is “VALUE” that is been also use to set the value of parameter in URL.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

      <head>

               <title>&lt;c:param&gt;,&lt;c:Url&gt;Tag Example In J.S.P</title>

     </head>

         <body>

                    <p><b><center><br>

                        <c:url value=”/definition.jsp” var=”cmpltAddrs”>

                               <c:param name=”Tag” value=”C_Url”/>

                               <c:param name=”Admin” value=”Dev”/>

                        </c:url>

                       ${cmpltAddrs}

                 </center></b></p>

         </body>

</html>

                    JSTL Core c param Tag

About Program…..

As per mentioned requirement taglib(tag library) from JSTL is been accessed. Then after all the required tag that made a structure of a program. In the body section the required values are set to be executed. The URL section we pass a URL of page that is been shown on the browser while execution the other parameters are the name and value will set in the output section as admin or user name. in the last all the HTML tags has to be closed.

JSTL Core c if Tag

By Dinesh Thakur

<c: if> this tag is similar to ‘IF’ control statement of java. This tag will use to execute when the given condition is true in the sense. Some attributes are used to implement in that tag like ‘test’ this is helpful to evaluate the condition….

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

    <head>

          <title>&lt;c:if&gt;Tag Example In J.S.P</title>

    </head>

       <body>

             <c:set var=”percentage” value=”65″/>

               <c:if test=”${percentage >= 60}”>

                     <p><b><center><br><c:out value=”You Have got First Division!”/>

               </c:if>

                   <c:if test=”${percentage < 60}”>

                         <c:out value=”You Have Got 2nd Division!”/>

                   </c:if>

                         <c:if test=”${percentage < 50}”>

                                <c:out value=”You Have Got 3rd Division!”/></b></center></p></br>

                         </c:if>

       </body>

</html>

                  JSTL Core c if Tag

About program

To call the taglib(tag library) for accessing the core tag in JSTL. After that declaring all the Html tags that is mandatory for procedure the way for tag using. In the body section if pass the value and put the condition if that condition falls true the required tag will evaluate the output on web browser.

JSTL Core c import Tag

By Dinesh Thakur

This tag <c: import> is used to import the absolute URL and show the content to another page. Some mandatory attributes are used to implement on this tag like “URL” this attribute use to retrieve and import the content from one page to another page. Other attributes like “scope” and “var” these are also used as required but this are not compulsory for using in this tag.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

   <head>

        <title>Thats The&lt;c:import&gt;Tag Example In J.S.P</title>

   </head>

     <body>

                    <c:import var=”desc” url=”/definition.jsp”/>

                    <c:out value=”${desc}”/>

     </body>

</html>

                  JSTL Core c import Tag

That’s the page where we gave the reference of another URL which will use to show the result on web browser.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

<head>

         <title>&lt;c:out&gt;Example In J.S.P</title>

</head>

      <body>

            <p><center><br><b><c:out value=”This is The Example Of C:IMPORT Tag…  “/></b></br></center></p>

     </body>

</html>

That’s the page where the URL will be imported and shows the output on web browser.

JSTL Core c forTokens Tag

By Dinesh Thakur

This Tag is been Only Used To Break string into Tokens and after that to retrieve them each from the tokens..this quite similar as <c: foreach> bt a major difference is b/w both in that the “Token” tag is been use within the “Delims”  to represent characters as delimiters…

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

<head>

       <title>&lt;c:forTokens&gt;Tag Example In J.S.P</title>

</head>

<body>

        <p><b><br /><center>

        <c:forTokens items=”Java,dotNet,Web are the Modern Age Computer Souls” delims=”,” var=”tkns”>

                <c:out value=”${tkns}”/>

       </c:forTokens>

       < /center></b></p>

       </body>

</html>

                      JSTL Core c forTokens Tag

About Program…..

As per to similar with <c: forEach> the only difference is that it uses “delims” that use to implement characters as “delimeteres”. As declaring all the required tags the body concept creates the function that will allow to get the desired output as the value of condition mentioning in the body section. that will present the value in token as a string type.

JSTL Core c forEach Tag

By Dinesh Thakur

The Core tag <c: forEach> that Tag is casually known as the substitute of While, do While in java Statements. Its    also works as Loop instance with the form of scriptlet in Java Server pages.

This tag also use some attributes like begin, end or step while the procedure of looping in the sense..the begin   attribute will works as to from where the condition will start in the loop by default its 0 .the step will use to skip the number from one to other. And the END attribute will use to get ending the loop circle…

     <%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

     <html>

       <head>

                 <title>&lt;c:forEach&gt;Tag Example in J.S.P</title>

       </head>

          <body>

                 <p><b><center>

                 <c:forEach var=”seq” begin=”2″ end=”20″ step=”2″>

                              <c:out value=”${seq}”/>

                 </c:forEach>

                 </center></b></p>

          </body>

     </html>

                                      JSTL Core c forEach Tag

 Let’s Descript About The <c: forEach> tag Program…

 As Mentioned Above we discuss about the tag that what it does and about its attributes. Now about to structure of program that how does the procedure goes on for executing the tag in proper way. Here we declare mandatory variable name and the value that is required for starting the loop here the other attribute we use step that will skip the number between sequences of loop. Then in last step we display the Output on web browser.

JSTL Core c choose Tag

By Dinesh Thakur

  <C:Choose>  Tag is similar to the Java Switch Statement In that case it allow us to choose desired statement that  has to be selected from substituted conditions. This tag has some more features like it has two more tags with it  Like <c:when> tag if the condition goes terminated to next step and the other one is <c: otherwise> works like default value in java switch case statement..And an attribute is also been used in the tag named “Test” that is used for evaluating Condition.

 <%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

<html>

<head>

            <title>&lt;c:choose&gt;,&lt;c:when&gt;&lt;c:otherwise&gt;Tag Example In J.S.P</title>

</head>

<body>

             <p><b><br /><center>

             <c:set var=”marks” scope=”session” value=”${800}”/>

             <p>Your Marks : <c:out value=”${marks}”/></p>

      <c:choose>

            <c:when test=”${marks >= 800}”>

                 ${” And You Got First Division”}

           </c:when>

           <c:when test=”${Marks < 800}”>

                ${“And You Got Second Division”}

          </c:when>

              <c:otherwise>

                  ${“Passed”}

             </c:otherwise>

      </c:choose></center></b></p>

</body>

</html>

                    JSTL Core c choose Tag

 Description about the Program Of <c: choose> tag in JSTL

 According to the requirement as we call the tag lib (tag library) for accessing the “CORE” tags In JSTL.

This tag is used as the java switch case statement in it’s own preference like with the <c: choose> we also use the   

<c: when> and <c: otherwise>. To declare all the mandatory HTML tags for functioning. In the first session we set    the variable name that will store the value of output and set the value as per the condition the first step has to be choose if its got terminated then other will be used to full fill the requirements like testing condition with the tag <c: when> and all the condition or statements goes cleared the default value will be printed on browser a s the output <c: otherwise> in JSTL. In the last all the tags will be closed.

JSTL Core c out Tag

By Dinesh Thakur

       This tag is Been used for Display the Result of an Expression. That is quite similar with the reference of<%…%>.

       In The program while using the C:Out tag we use some kind of attributes that has with it like we use “Value” this 
       will be used to inform about Output that will be show on the web Browser while Compiling The  program.

        <%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

        <html>

        <head>

             <title>&lt;c:out&gt;Example In J.S.P</title>

      </head>

      <body>

                  <p><center><br><b><c:out value=”${‘This is The Example Of C:Out Tag’}”/></b></br></center></p>

     </body>

     </html>    

 

                      JSTL Core c out Tag 

Let’s take a look on the Program…

To elaborate the C: Out (JSTL) tag as per we use to call the taglib(tag library) line in the start of Program with the         prefix of “c”. After that the motto of this program to show the output of expressions. Here we call all the required    HTML tags like Head, Title and body tags etc. in body tag we put the parameter in required value part. And then it will be used to print the result on web browser while compiling.  

JSTL Core c catch Tag

By Dinesh Thakur

<c:catch> JSTL Tag used for exception handling.. In this Program we are going to discuss about exception handling using <c:catch> core tag.

Here We Declare Variable Name That will be used to store the exception Message in it if there will be any Exception.

To explain the Exception handling we will use The example of Arithmetic Exception That will be the Integer Divided by Zero and then return the Exception Message…

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %

<html>

<head>

     <title>&lt;c:catch&gt;Example In J.S.P</title>

</head>

<body>

      <c:catch var =”value”>

           <% int x = 15/0;%>

      </c:catch>

                  <c:if test = “${value != null}”>

                 <br><br><br><p><center><b>The Exception is Been Caught as : ${value} <br/>

                There is an Exception: ${value. message} <b></center></p>

          </c:if>

        </body>

 </html>

                  JSTL Core <c:catch> Tag

Some Thing to Descript about the Program….

Here in the Starting Of program We Use Prefix Line or tag Library code for ‘Core’ tags (JSTL) in J.S.P….

Then According to mentioned Requirement we use HTML tags that will be useful for the presentation on browser while executing Or Output…Like We use title Tag that will represent the Title of web page on the browser. Then starting of Body tag all the effects of Tags in HTML will be done by it. In the Body tag the core of The Program in this section the required function will be executed. In last all the tags has to be closed…

« Previous Page

Primary Sidebar

Java Server Pages

Java Server Pages

  • JSP - Home
  • JSP - Advantages
  • JSP - Architecture
  • JSP - Life Cycle
  • JSP - Servlet Disadvantages
  • JSP - PrintWriter Vs JspWriter
  • JSP - Session Tracking
  • JSP - Stateless Protocol
  • JSP - Hidden Form Fields
  • JSP - Program Structure
  • JSP - Bill Discount Program
  • JSP - Scripting Elements
  • JSP - fn:length()
  • JSP - fn:split()
  • JSP - fmt formatNumber Tag
  • JSP - Servlet Communication
  • JSP - fn:replace()
  • JSP - fmt:parseNumber Tag
  • JSP - fmt:parseDate Tag
  • JSP - fn:substring()

Other Links

  • JSP - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW