Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. JSP directives
1. page directive
2. Attributes of page directive
The jsp directives are messages that tells the web container how to translate a JSP
page into the corresponding servlet.
page directive
include directive
taglib directive
import
contentType
extends
info
buffer
language
isELIgnored
isThreadSafe
autoFlush
session
pageEncoding
errorPage
isErrorPage
1)import
2)contentType
The contentType attribute defines the MIME(Multipurpose Internet Mail Extension) type
of the HTTP response.The default value is "text/html;charset=ISO-8859-1".
3)extends
The extends attribute defines the parent class that will be inherited by the generated
servlet.It is rarely used.
4)info
This attribute simply sets the information of the JSP page which is retrieved later by
using getServletInfo() method of Servlet interface.
5)buffer
The buffer attribute sets the buffer size in kilobytes to handle output generated by the
JSP page.The default size of the buffer is 8Kb.
6)language
The language attribute specifies the scripting language used in the JSP page. The default
value is "java".
7)isELIgnored
We can ignore the Expression Language (EL) in jsp by the isELIgnored attribute. By
default its value is false i.e. Expression Language is enabled by default. We see
Expression Language later.
8)isThreadSafe
Servlet and JSP both are multithreaded.If you want to control this behaviour of JSP
page, you can use isThreadSafe attribute of page directive.The value of isThreadSafe
value is true.If you make it false, the web container will serialize the multiple
requests, i.e. it will wait until the JSP finishes responding to a request before passing
another request to it.If you make the value of isThreadSafe attribute like:
9)errorPage
The errorPage attribute is used to define the error page, if exception occurs in the
current page, it will be redirected to the error page.
1. //index.jsp
2.
3. <%@ page errorPage="myerrorpage.jsp" %>
4.
5. <%= 100/0 %>
6. </html>
10)isErrorPage
The isErrorPage attribute is used to declare that the current page is the error page.
Note: The exception object can only be used in the error page.
1. //myerrorpage.jsp
2. <html>
3. <%@ page isErrorPage="true" %>
4.
5. Sorry an exception occured!<br/>
6. The exception is: <%= exception %>
7. </html>
Jsp Include Directive
The include directive is used to include the contents of any resource it may be jsp file, html
file or text file. The include directive includes the original content of the included resource at
page translation time (the jsp page is translated only once so it will be better to include
static resource).
Code Reusability
In this example, we are including the content of the header.html file. To run this example
you must create an header.html file.
1. <html>
2. <body>
3.
4. <%@ include file="header.html" %>
5.
6. Today is: <%= java.util.Calendar.getInstance().getTime() %>
7.
8. </body>
9. </html>
Note: The include directive includes the original content, so the actual page size
grows at runtime.
JSP Taglib directive
The JSP taglib directive is used to define a tag library that defines many tags. We use the
TLD (Tag Library Descriptor) file to define the tags. In the custom tag section we will use
this tag so it will be better to learn it in custom tag.
In this example, we are using our tag named currentDate. To use this tag we must specify
the taglib directive so the container may get information about the tag.
1. <html>
2. <body>
3.
4. <%@ taglib uri="http://www.javatpoint.com/tags" prefix="mytag" %>
5.
6. <mytag:currentDate/>
7.
8. </body>
9. </html>
Interview Questions
2. What is the requirement of a tag library?
A collection of custom tags is called a Tag Library. Recurring tasks are handled more easily
and reused across multiple applications to increase productivity. They are used by Web
Application designers who focus on presentation rather than accessing database or other
services. Some popular libraries are String tag library and Apache display tag library .
JSP is a standard extension of Java and is defined on top of Servlet extensions. Its goal is to
simplify management and creation of dynamic web pages. It is platform-independent,
secure, and it makes use of Java as a server side scripting language.
Objects created by web container and contain information regarding a particular request,
application or page are called Implicit Objects. They are :
1. A form filled by the user is submitted to the server using POST or GET method. The state
in the database and business model are updated.
3. A view is loaded by the browser using the GET command and no user data is sent. This is
safe from multiple submits as it is a separate JSP page.
Yes, JSP is easily extensible by use and modification of tags, or custom actions,
encapsulated in tag libraries.
7. Differentiate between response.sendRedirect(url) and <jsp:forward page = …> .
<jsp.forward> element forwards the request object from 1 JSP file to another. Target file
can be HTML, servlet or another JSP file, but it should be in the same application context as
forwarding JSP file.
sendRedirect send HTTP temporary redirect response to the browser. The browser then
creates a new request for the redirected page. It kills the session variables.
8. Can a subsequent request be accessed with one’s servlet code, if a request attribute is already
sent in his JSP?
The request goes out of scope, thus, it cannot be accessed. However, if a request attribute
is set in one’s servlet, then it can be accessed in his JSP.
A JSP is a server side component and the page in translated to a Java servlet, and then
executed. Only HTML code is given as output
Static pages are always included using JSP include directive. This way the inclusion is
performed in the translation phase once. Note that a relative URL must be supplied for file
attribute. Although static resources may be included, it is not preferred as each request
requires inclusion.
10. Why is it that JComponent have add() and remove() methods but Component doesn’t?
12. How can the output of JSP or servlet page be prevented from being cached by the browser?
Using appropriate HTTP header attributes to prevent the dynamic content output by a JSP
page from being cached by the browser.
13. How to restrict page errors display in a JSP page?
By setting up an “ErrorPage” attribute of PAGE directory to the name of the error page in
the JSP page, and then in the error jsp page set “isErrorpage=”TRUE”, Errors can be
stopped from getting displayed.
They are XML tags, which direct the server to using existing components or control behavior
of JSP Engine. They consist of a typical prefix of “jsp:” and action name.
Java
<jsp:include/>
<jsp:getProperty/>
<jsp:include/>
<jsp:getProperty/>
<jsp:forward/>
<jsp:setProperty/>
<jsp:usebean/>
<jsp:plugin/>
The first tag acts as a function call between two Jsp’s. It is executed each time client page
is accessed by the client. It is useful to modularize the web application. New content is
included in the output.
The second tag content of file is textually embedded having similar directive. The changed
content is not included in the output. It is helpful when code from one jsp is required by
several jsp’s.
Yes, it is possible. But it is not preferred because init() was developed because earlier Java
versions could not invoke constructors with arguments dynamically. So they could not
assign a servletConfig. Today, however, servlet containers still call only no-arg constructor.
So there is no access to servletContext or servletConfig.
18. Explain JSP Output comments?
Expression tag is used to insert Java values directly in the output. Its syntax is
<%=expression%>
It contains a scripting language expression that is evaluated, then converted to a string, and
then inserted where the expression comes in JSP file.
It a JSP tag that encloses Java code in JSP pages. Their syntax is <% %>. Code written in
scriptlet executes every time the program is run.
22. How can information from one JSP be passed to another JSP?
Java
<jsp:useBean>
<jsp:useBean>
id="beanInstName"
scope= "page | application"
class="ABC.class" type="ABC.class"
</jsp:useBean>
This tag creates an instance of java bean. It firstly tries to find if bean instance already exist
and assign stores a reference in the variable. Type is also specified; otherwise it
instantiates from the specified class storing a reference in the new variable.
It redirects the browser to JSP page error.jsp if any uncaught exception is faces during
request handling. It is an error processing page.
25.Why does _jspService() start with an ‘_’ but other lifecycle methods do not?
Whatever content made in a jsp page goes inside the _jspService() method by the
container. If it is override, the compiler gives an error, but the other 2 lifecycles can be
easily override. So ‘_’ shows that we cannot override this method.
<jsp:useBean> tag is used to use any java object in the jsp page. Some scope values are :
<%–JSP Comment–%>
<!–HTML comment–>
<%–JSP Comment–%>
<!–HTML comment–>
28.Can Static method be Override?
We can declare static methods with same signature in subclass, but it is not considered
overriding as there won’t be any run-time polymorphism. Hence the answer is ‘No’.
JSP directives are messages to JSP Engine. They serve as a message from page to
container and control the processing of the entire page. They can set global values like
class declaration. They do not produce output and are enclosed in <%@….%>
Page Directives inform the JSP Engine about headers and facilities that the page receives
from the environment. It is found at the top of all JSP pages. Its syntax is <%@ page
attribute=”value”>
3)isELIgnored : It shows whether EL expressions are ignored when JSP translates into a servlet.
The include directive statically inserts the contents of a resource into the current JSP. It helps in the
reuse of code without duplication. and includes contents of the file at translation time. Its syntax is as
follows <%@ include file=”Filename”%>.
33. What are standard actions in JSP?
They affect overall runtime behaviour of a page and response sent to the client. They are used to
include a file at request time, to instantiate a JavaBean or find one. They are also used to generate a
browser-specific code or forward a request to a new page.
It is used to give values to properties of beans that have been referenced beforehand.
<jsp:useBean id=”ABC”…/>
By adding </jsp.useBean> at the end of the code, the condition for execution is inverted i.e. It is not
executed if existing object was found and only if a new object was instantiated.
This action helps in insertion of a specific object in the browser or embed the element needed to
specify the running of applet using Java plugin.
Javascript is used for the client-side validation. It takes place within the browser. Javascript is used to
submit the form data if validation is successful. Validation errors require no extra network trip
because form cannot be submitted.
Validation is also carried out in the server after submission. If validation fails, extra network trip is
required to resend the form to the client.
38. What is Translation Phase?
JSP engine translates and compiles a JSP file to a servlet. This servlet moves to the execution phase
where requests and responses are handled. They are compiled for the first time they are accessed
unless manually compiled ahead of time. The manual or explicit compilation is useful for long and
convoluted programs.
Object cloning is used to create an exact copy of an object by typing the same code or using various
other techniques.
JSP page automatically create sessions for requests. By typing the following, it can be avoided.
1 <%@ page session=”false” %>
Whenever a JSP page is about to be destroyed, the container invokes the jspDestroy() method from
the javax.servlet.jsp.JspPage interface. Servlets destroy methods are similar to it. It can be easily
overridden to perform cleanup, like when closing a database connection.
It is an action used with include or forward standard actions. It helps in passing the parameter names
and values to a resource.
A static method is of the class and not the object of a class. It can be invoked without instance of a
class. Static members can also access the static data and change its value.
Scripting can be easily disabled by setting scripting-invalid element of the deployment descriptor to
true. It is a sub-element of property group. Its can be false as well.
JSP Declaration are tags used in declaring variables. They are enclosed in <%!%> tag. They are used
in declaring functions and variables.
response.setHeader(“Cache-Co
response.setDateHeader(“Expir
response.setDateHeader(“Expires”, 0);
%>
JSP is a technology on the server’s side to make content generation simple. They are document
centric, whereas servlets are programs. A Java server page can contain fragments of Java program,
which execute and instantiate Java classes. However, they occur inside HTML template file. It
provides the framework for development of a Web Application.
Servlet – Interview Question
1. What is a Servlet?
A servlet is a Java technology and it is managed by a container called servlet engine. It
generates dynamic content and interacts with client through Request and Response.
4. What is a filter?
A filter is nothing but a piece of code which can be reusable that will be transforming the content
of HTTP requests, response and header information.
5. How can we refresh automatically when new data has entered the database?
Refresh in Client side and Server Push can be performed to refresh automatically when new
data is entered into the database.
Servlet
11. What is the difference between Servlet Request and Servlet Context when calling a
Request Dispatcher?
Relative URL can be called when Servlet Request is used and Relative URL is not used when
using Servlet Context.
ServletContext is an application specific object and it is shared by all servlet. It belongs to one
application in one JVM.
50. What exception should be thrown when servlet is not properly initialized?
Servlet exception or an Unavailable exception is thrown when it is not properly initialized.
Struts – Interview Question
Q1. What are the components of Struts Framework?
1. Java Servlets
2. JSP (Java Server Pages)
3. Custom Tags
4. Message Resources
Q2. What’s the role of a handler in MVC based applications?
Ans:. It’s the job of handlers to transfer the requests to appropriate models as they are
bound to the model layer of MVC architecture. Handlers use mapping information from
configuration files for request transfer.
Ans: Struts based applications use MVC design pattern. The flow of requests is as follows:
User interacts with View by clicking any link or by submitting any form.
Upon user’s interaction, the request is passed towards the controller.
Controller is responsible for passing the request to appropriate action.
Action is responsible for calling a function in Model which has all business logic
implemented.
Response from the model layer is received back by the action which then passes it towards
the view where user is able to see the response.
Q4. Which file is used by controller to get mapping information for request routing?
Ans: Controller uses a configuration file “struts-config.xml file to get all mapping information
to decide which action to use for routing of user’s request.
Ans: In Struts, Action Class acts as a controller and performs following key tasks:
import javax.servlet.http.HttpServletRequest;
1 import org.apache.struts.action.*;
2 public class testForm extends ActionForm {
3
private String Id=null;
4
5 private String State=null;
6 public void setId(String id){
7 this.Id=id;
8 }
9 public String getId(){
10 return this.Id;
11 }
12
public void setState(String state){
13
14 this.State=state;
15 }
16 public String getState(){
17 return this.State;
}
Q7. What are the two types of validations supported by Validator FrameWork?
Ans: Validator Framework is used for form data validation. This framework provides two types
of validations:
Then Validation rules are defined in validation.xml file. If a form contains email field and we
want to enable client side validation for this field, following code is added in validation.xml file:
1 <form name="testForm">
2 <field property="email"
3 depends="required">
4 <arg key="testForm.email"/>
5 </field>
6 </form>
Q10. How action-mapping tag is used for request forwarding in Struts configuration file?
Ans: In Struts configuration file (struts-config.xml), forwarding options are defined under action-
mapping tag.
In the following example, when a user will click on the hyperlink test.do, request will be
forwarded to/pages/testing.jsp using following configurations from struts-config.xml file:
This forwarding will take place when user will click on following hyperlink on the jsp page:
Ans: In Struts, action class provides two important methods which can be used to avoid duplicate
form submissions.
saveToken() method of action class generates a unique token and saves it in the user’s session.
isTokenValid() method is used then used to check uniqueness of tokens.
Q12. In Struts, how can we access Java beans and their properties?
Ans: Bean Tag Library is a Struts library which can be used for accessing Java beans.
Q13. Which configuration file is used for storing JSP configuration information in Struts?
Ans: For JSP configuration details, Web.xml file is used.
In the following example, execute method will return an object of actionForward defined in
struts-config.xml with the name “exampleAction”:
import javax.servlet.http.HttpServletRequest;
1 import javax.servlet.http.HttpServletResponse;
2
3
import org.apache.struts.action.Action;
4
5 import org.apache.struts.action.ActionForm;
6 import org.apache.struts.action.ActionForward;
7 import org.apache.struts.action.ActionMapping;
8
9 public class actionExample extends Action
10 {
11 public ActionForward execute(
12 ActionMapping mapping,
13
ActionForm form,
14
15 HttpServletRequest request,
16 HttpServletResponse response) throws Exception{
17 return mapping.findForward("exampleAction");
18 }
}
Q15. What’s the difference between validation.xml and validator-rules.xml files in Struts
Validation framework?
Ans: In Validation.xml, we define validation rules for any specific Java bean while in validator-
rules.xml file, standard and generic validation rules are defined.
Q16. How can we display all validation errors to user on JSP page?
Ans: To display all validation errors based on the validation rules defined in validation.xml file,
we use <html:errors /> tag in our JSP file.
1 <global-exceptions>
2
3 <exception key="test.key"
4
5 Type="java.lang.NullPointerException"
6
7 Path="/WEB-INF/errors/error_page.jsp"
8
9 </global-exceptions>
Q20. What’s the difference between Jakarta Struts and Apache Struts? Which one is
better to use?
Ans: Both are same and there is no difference between them.
1 <taglib>
2
3 <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
4
5 <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
6
7 </taglib>
2. Session Scope: Formbean values are available for all requests in the current session.
Ans: The best scenario to use SwitchAction class is when we have a modular application with
multiple modules working separately. Using SwitchAction class we can switch from a resource
in one module to another resource in some different module of the application.
Q28. What steps are required to for an application migration from Struts1 to Struts2?
Ans: Following Steps are required for Struts1 to Struts2 migration:
Struts also lack proper documentation and for many of its components, users are unable to get
proper online resources for help.
This approach helps to keep the code clean as developer doesn’t need to embed all error
messages inside code.
Q33. Can I have html form property without associated getter and setter formbean
methods?
Ans: For each html form property, getter and setter methods in the formbean must be defined
otherwise application results in an error.
Q35. For a single Struts application, can we have multiple struts-config.xml files?
Ans: We can have any number of Struts-config.xml files for a single application.
We need following configurations for this:
1 <servlet>
2
3 <servlet-name>action</servlet-name>
4
5 <servlet-class>
6
7 org.apache.struts.action.ActionServlet
8
9 </servlet-class>
10
11 <init-param>
12
13 <param-name>config</param-name>
14
15 <param-value>
16
17 /WEB-INF/struts-config.xml
18
19 /WEB-INF/struts-config_user.xml
20
21 /WEB-INF/struts-config_admin.xml
22
23 </param-value>
24
25 </init-param>
26
27 .............
28
29 .............
30
31 </servlet>
Ans: Struts support all types of models including Java beans, EJB, CORBA. However, Struts
doesn’t have any in-built support for any specific model and it’s the developer’s choice to opt for
any model.
Q39. What configuration changes are required to use resource files in Struts?
Ans: Resource files (.properties files) can be used in Struts by adding following configuration entry in
struts-config.xml file:
<message-resources parameter=”com.login.struts.ApplicationResources”/>
Action Class
ActionForm Class
ActionMapping Class
ActionForward Class
ActionServlet Class
Q42. Can we handle exceptions in Struts programmatically?
Ans: Yes we can handle exceptions in Struts programmatically by using try, catch blocks in the
code.
1 try {
2
3 // Struts code
4
5 }
6
7 Catch (Exception e) {
8
9 // exception handling code
10
11 }
Ans: Although Struts framework is based on J2EE technologies like JSP, Java Beans, Servlets
etc but it’s not a part of J2EE standards.
1 <pre><action-mappings>
2 <action path="/login"
3 type="login.loginAction"
4 name="loginForm"
5 input="/login.jsp"
6 scope="request"
7 validate="true">
8 <forward name="success" path="/index.jsp"/>
9 <forward name="failure" path="/login_error.jsp"/>
10 </action>
11 </action-mappings>
Q47. What are the steps required for setting up validator framework in Struts?
Ans: Following Steps are required to setup validator framework in Struts: – Wrong Spelling
1. In WEB-INF directory place valdator-rules.xml and validation.xml files.
2. Enable validation plugin in struts-config.xml files by adding following:
1 <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
2 <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
3 /WEB-INF/validation.xml"/>
4 </plug-in>
JSP
HTML
XML/XSLT
WML Files
Velocity Templates
Servlets
It must have a no argument constructor.
It should have public getter and setter methods for all its properties.
Q50. Which library is provided by Struts for form elements like check boxes, text boxes
etc?
Ans: Struts provide HTML Tags library which can be used for adding form elements like text
fields, text boxes, radio buttons etc.
Web page
A web page or webpage is a document commonly written in HyperText Markup Language
(HTML) that is accessible through the Internet or other network using a browser. A web page is
accessed by entering a URL address and may contain text, graphics, and hyperlinks to other
web pages and files. The page you are reading now is an example of a web page.
In the above example of a URL, the web page is "url.htm" and is always the last part of
the URL. For URL's that do not have an ending .htm, .html, .php, .cgi, .pl, or other file
extension the server is loading the default index.htm in that directory. For example, on
our contact page URL ( http://www.computerhope.com/contact/ ) there is no web page,
so the default index file loads from the contact/ directory.
Eg: Dynamic pages are also what let users log into websites to see personalized content.
Web browser
A web browser (commonly referred to as abrowser) is a software application for retrieving,
presenting, and traversing information resources on the World WideWeb. An information
resource is identified by a Uniform Resource Identifier (URI/URL) and may be a web page,
image, video or other piece of content
As a client/server model, the browser is the client run on a computer that contacts the
Web server and requests information. The Web server sends the information back to the Web
browser which displays the results on the computer or other Internet-enabled device that
supports a browser.
Mobile Browsers
Also, there are a number of browsers that are designed to access the Web using a mobile
device. A mobile browser, also called a microbrowser, is optimized to display Web content on
smaller mobile device screens and to perform efficiently on these computing devices, which
have far less computing power and memory capacity as desktop or laptop. Mobile browsers are
typically "stripped down" versions of Web browsers and offer fewer features in order to run well
on mobile devices.
Web server
Web servers are computers that deliver (serves up) Web pages. Every Web server has an IP
address and possibly a domain name. For example, if you enter the URL
http://www.webopedia.com/index.html in your browser, this sends a request to the Web server
whose domain name is webopedia.com. The server then fetches the page named index.html and
sends it to your browser.
Any computer can be turned into a Web server by installing server software and connecting the
machine to the Internet. There are many Web server software applications, including public
domain software and commercial packages.
Web site
A site (location) on the World Wide Web. Each Web site contains ahome page, which is the
first document users see when they enter the site. The site might also contain additional
documents and files. Each site is owned and managed by an individual, company or
organization.
HTTP
HTTPS
HTTPS (HTTP over SSL or HTTP Secure) is the use of Secure Socket Layer (SSL) or Transport
Layer Security (TLS) as a sublayer under regular HTTP application layering. HTTPS encrypts
and decrypts user page requests as well as the pages that are returned by the Web server.
JSTL (JSP Standard Tag Library)
The JSP Standard Tag Library (JSTL) represents a set of tags to simplify the JSP
development.
Advantage of JSTL
1. Fast Developement JSTL provides many tags that simplifies the JSP.
2. Code Reusability We can use the JSTL tags in various pages.
3. No need to use scriptlet tag It avoids the use of scriptlet tag.
core tags The JSTL core tag provide variable support, URL management, flow
control etc. The url for the core tag
is http://java.sun.com/jsp/jstl/core . The prefix of core tag is c.
sql tags The JSTL sql tags provide SQL support. The url for the sql tags
is http://java.sun.com/jsp/jstl/sqland prefix is sql.
xml tags The xml sql tags provide flow control, transformation etc. The url for
the xml tags ishttp://java.sun.com/jsp/jstl/xml and prefix is x.
functions tags The functions tags provide support for string manipulation and string
length. The url for the functions tags
is http://java.sun.com/jsp/jstl/functions and prefix is fn.
c:catch
Example of c:catch
Let's see the simple example of c:catch.
c:out
It is just like JSP expression tag but it is used for exression. It renders data to the page.
Example of c:out
Let's see the simple example of c:out.
index.jsp
1. <form action="process.jsp" method="post">
2. FirstName:<input type="text" name="fname"/><br/>
3. LastName:<input type="text" name="lname"/><br/>
4. <input type="submit" value="submit"/>
5. </form>
process.jsp
1. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
2. First Name:<c:out value="${param.fname}"></c:out><br/>
3. Last Name:<c:out value="${param.lname}"></c:out>
c:import
It is just like jsp include but it can include the content of any resource either within server
or outside the server.
Example of c:import
Let's see the simple example of c:import to display the content of other site.
index.jsp
1. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
2. <h1>ABC.com</h1>
3. <hr/>
4. <c:import url="http://www.javatpoint.com"></c:import>
index.jsp
1. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
2. <h1>ABC.com</h1>
3. <hr/>
4. <c:import var="data" url="http://www.javatpoint.com"></c:import>
5.
6. <h2>Data is:</h2>
7. <c:out value="${data}"></c:out>
c:forEach
It repeats the nested body content for fixed number of times or over collection.
Example of c:forEach
Let's see the simple example of c:forEach.
Example of c:if
Let's see the simple example of c:if.
c:redirect
1. Eliminates the need of scriptlet tag The custom tags eliminates the need of
scriptlet tag which is considered bad programming approach in JSP.
2. Separation of business logic from JSP The custom tags separate the the business
logic from the JSP page so that it may be easy to maintain.
3. Re-usability The custom tags makes the possibility to reuse the same business logic
again and again.
Syntax to use custom tag
There are two ways to use the custom tag. They are given below:
The javax.servlet.jsp.tagext package contains classes and interfaces for JSP custom tag API.
The JspTag is the root interface in the Custom Tag hierarchy.
JspTag interface
The JspTag is the root interface for all the interfaces and classes used in custom tag. It is a
marker interface.
Tag interface
The Tag interface is the sub interface of JspTag interface. It provides methods to perform
action at the start and end of the tag.
There are four fields defined in the Tag interface. They are:
public static int EVAL_PAGE it evaluates the JSP page content after the custom
tag.
public static int SKIP_BODY it skips the body content of the tag.
public static int SKIP_PAGE it skips the JSP page content after the custom tag.
IterationTag interface
The IterationTag interface is the sub interface of the Tag interface. It provides an additional
method to reevaluate the body.
TagSupport class
The TagSupport class implements the IterationTag interface. It acts as the base class for
new Tag Handlers. It provides some additional methods also.
Expression Language (EL) in JSP
The Expression Language (EL) simplifies the accessibility of data stored in the Java Bean component, and
other objects like request, session, application etc.
There are many implicit objects, operators and reserve words in EL.
It is the newly added feature in JSP technology version 2.0.
There are many implicit objects in the Expression Language. They are as follows:
pageScope it maps the given attribute name with the value set in the page scope
requestScope it maps the given attribute name with the value set in the request scope
sessionScope it maps the given attribute name with the value set in the session scope
applicationScope it maps the given attribute name with the value set in the application
scope
In this example, we have created two files index.jsp and process.jsp. The index.jsp file gets
input from the user and sends the request to the process.jsp which in turn prints the name
of the user using EL.
index.jsp
1. <form action="process.jsp">
2. Enter Name:<input type="text" name="name" /><br/><br/>
3. <input type="submit" value="go"/>
4. </form>
process.jsp
1. Welcome, ${ param.name }
Example of Expression Language that prints the value set in the session scope
In this example, we printing the data stored in the session scope using EL. For this purpose,
we have used sessionScope object.
index.jsp
process.jsp
1. Value is ${ sessionScope.user }
Precedence of Operators in EL
There are many operators that have been provided in the Expression Language. Their
precedence are as follows:
[] .
()
* / div % mod
+ - (binary)
== != eq ne
&& and
|| or
?:
Reserve words in EL
There are many reserve words in the Expression Language. They are as follows:
lt Le gt ge
eq Ne true false