When a JSP include directive is used, the included file's code is added into the added JSP page at page
translation time, this happens before the JSP page is translated into a servlet. While if any page is included
using action tag, the page's output is returned back to the added page. This happens at runtime
Use the following ways to pass control of a request from one servlet to another or one jsp to another.
The RequestDispatcher object ‘s forward method to pass the control.
The response.sendRedirect method
Give a sample JSP configuration in the deployment descriptor.
1. Management of scriptlet elements on the page,
2. Controlling the execution of expressions in a language
3. URL pattern definition for encoding,
4. Determining the size of the buffer that is used for objects on the page
5. Identification of resource groups corresponding to a URL pattern to be processed as an XML document.
You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done
by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.
jsplnit(): Initially, the method is called to initialize servlet and is called only for once.
_jspService(): The container calls this method and then processes the request accordingly.
jspDestroy(): Before the demolition of instance, this method is called.
SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object including PreparedStatement and CallableStatement objects, or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object.
It is possible to make the Finally Clause to not to fail by using System.exit(1); in the try block.
JSP is preferred for creating web-based client program. Because no plug-ins/security policy files are needed on the client systems whereas applet does. Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs.
Deleting the Session Data involves the following steps.
1. Remove a particular attribute: public void removeAttribute(String name) method is called to delete the value associated with the particular key.
2. Delete the whole session: public void invalidate() method is called to discard an entire session.
3. Setting the Session timeout: public void setMaxInactiveInterval(int interval) method is called to set the timeout for a session individually.
4. Log the user out: The logout is called to log the client out of the Web server and invalidate all sessions belonging to all the users.
5. web.xml Configuration: In Tomcat, using the above-mentioned methods, one can configure session time out in web.xml file as follows.
Setting cookies with JSP involves the following steps:
1. Creating a Cookie object: Cookie constructor is called with a cookie name and a cookie value, both are strings.
2. Setting the maximum age: setMaxAge is used to specify the length of the cookie(in seconds) should be valid.
3. Sending the cookie into the HTTP response headers: response.addCookie is used to add cookies in the HTTP response header.
You can use the errorPage attribute of the page directive to have uncaught runtime exceptions automatically
forwarded to an error processing page.
redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request
processing. Within error.jsp, if you indicate that it is an error-processing page, via the directive:
the Throwable object describing the exception may be accessed within the error page via the exception implicit
Some of the Major Advantages of JSP over Pure Servlets are as discussed below:
It is more convenient to write and modify normal HTML than to have plenty of println statements that generate the HTML.
Embedding of Java code in HTML pages.
Creation of database-driven Web applications.
Server-side programming capabilities.
We have 4 scope objects.
These are useful carry the information from .jsp file to another .jsp file.
? application (context)
In the all scope objects application scope object having highest accessibility that means we can use that scope object information from all browser as well windows also.
Session scope object data can be accessible within the same browser but all windows.
Request scope object data can be accessible only one window, once response handover to browser request scope object data will be destroyed.
Page scope object data can be accessible only within the same page.
The advantages of JSP over ASP are as follows:
The dynamic part of the code is written in Java, not in Visual Basic or the Microsoft-specific language. Hence, it is powerful and easier to use.
It is portable to other operating systems and Non-Microsoft Web servers.
You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and
jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database
connections, network connections, and so forth for the JSP page. It is good programming practice to free any
allocated resources within jspDestroy().
The jspInit() and jspDestroy() methods are each executed just once during the lifecycle of a JSP page and are
typically declared as JSP declarations.
JSP includes directives that are used to deploy static files in JSP. In this way, the inclusion process is performed only once as the resources are included, but before that, the URL must be given for file.
There are five tags available in JSTL
1. Core tags
2. Function tags
3. SQL tags
4. XML tags
5. Internationalization tags
It is a JSP library that has predefined tags and soothes the process of developing JavaServlet Page.
The object cloning is a process of creating an exact copy of the existing object. The clone() method of Object class is used to create the clone an existing object. The class, whose object the user tries to clone is expected to implement the java.lang.Cloneable interface. If it does not implement the Cloneable interface, then the clone() method generates the CloneNotSupportedException.
1. protected Object clone() throws CloneNotSupportedException
Yes, We can use a constructor in place of init() method. 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. However, servlet containers still call an only no-arg constructor. So there is no access to servletContext or servletConfig.
We can stop errors in display in a JSP Page by setting up an “ErrorPage” attribute of the PAGE directory to the name of the error page in the JSP page, and then in the error JSP page set “isErrorpage=”TRUE”.
Static pages can be included in a JSP using the 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.
The Web Container creates certain objects that include the information related to a particular Request, Application or a Page. These Objects are called as Implicit Objects. The Implicit Objects in the JSP are as follows:
You can use a client-side Refresh or Server Push.
YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated
in tag libraries.
JSP pages the preferred API for creating a web-based client program because no plug-ins or security policy files are needed on the client systems(applet does). Also, JSP pages
enable cleaner and more module application design because they provide a way to separate applications
programming from web page design. This means personnel involved in web page design do not need to
understand Java programming language syntax to do their jobs.
Implicit objects are objects that are created by the web container and contain information related to a particular
request, page, or application. They are:
Saikat Banerjee Page 2
The Three tags used in the JSP Bean development are as follows:
Custom Tags in JSP are created using the following steps.
1.Creating the Tag Handler Class
2.Creating the TLD File
3.Creating the JSP File
Creating the Tag Handler Class:
To create a Tag Handler Class, we need to inherit the TagSupport Class and then override doStartTag() method. To write the data for JSP, we need to use the JspWriter class. The PageContext class provides getOut() method which returns the instance of the JspWriter class. Later, the TagSupport class provides an instance of pageContext by default.
Creating the TLD File:
TLD stands for Tag Library Descriptor file. It contains the information related to the tag and Tag Hander classes. It must be held inside the WEB-INF directory.
Creating the JSP File:
We will be specifying the path of the TLD file directly. It is recommended to use the URI name instead of full a path of the TLD file. It uses taglib directive to use the tags defined in the TLD file.
3. Floating point
To forward the JSP servlet request, one can use the “forward” tag before that one needs to send the URL pattern of the servlet.
Below is the list of few attributes of the JSP page directive briefly explained.
1. Import attribute:- Used to guide containers to import java classes and interfaces and produce servlet side by side. It is also one of the most used attributes.
2. Extends attribute:- It defines the superclass produced by servlet code, and it can be used when one has expanded HttpServlet.
JSP page directives apply to the whole page and offer a number of attributes in one single page. It is also possible to have numerous page directives applied to a single JSP page.
Custom Tags in JSP are created using the following steps.
1. Creating the Tag Handler Class
2. Creating the TLD File
3. Creating the JSP File
The objects which are created or given by the container to implement our jsp logic are called Implicit Objects.
We have 9 implicit objects.
The major difference between ServletContect and PageContext is, the ServletContext is designed to provide information about the Container and on the other hand, the PageContext is designed to provide information about the Request.
The Literals used in JSP are as follows:
The JSP implicit objects are established by the servlet while converting JSP to the servlet container. Nine JSP implicit objects can be used in a JSP page directly. Two implicit items are part of the _jspService() method argument. Seven out of nine implicit objects are asserted as a local variable of _jspService().
As the name hints, the JSP declarations are chiefly utilized to declare methods and class variables on a JSP page. At the same time, it is significant to keep in mind the exceptions to the application of the same. Declarations are not included in the service method when a JSP is translated to a servlet.
It is useful for writing the code within the _jspService(.........,.........). It is useful for declaring local variables, final variables, method calling statements, doing operations (logic).We can write one or more statements and every statement ended with semicolon.
This tag is useful writing code/programming elements at class level.
The programming elements may be blocks, constructors, variables, methods.
The code is always added to our class outside of the _jspService(-,-).
We can write multiple statements within the single declaration tag.
Every statement should be ended with semicolon.
Syntax: <%! ————– %>
Include directive and include action, as the name suggests, is the method used to include the result of some other page to the required destination.
The dynamic part of JSP is written in java and hence proves to be easier and powerful. It can effortlessly port itself to any operating system.
There are three types of comments we can use in JSP.
1. HTML comment <!– comment text –>
This tag is not ignored by the JSP container, this tag will be placed into Page Implementation class (PIC), handover to browser by Servlet container, but browser will ignores.
2. JSP comment <%– comment text –%>
This tag is ignored by the Jsp Container
3. Java comment: If we are writing java comments outside of html comment and jsp comment these comments will be treated as html code.
If we are writing java comments in declarative and scriptlet tag these comments not ignored by the jsp container these comments are placed into PIC in translation phase, but in compilation jsp container ignores.
We have 5 types of tags in JSP.
1. Scripting tags
2. Directive tags.
3. Standard action tags
4. Custom action tags
The JSP text files combine all the available files of HTML, XML code, and elements and the previously rooted java code.
The JavaServer page is the java servlet that acts as the user interface for java based applications.
The JSP tags generally start with <% and end with %>
JavaServer Pages is a technology employed to develop web pages that aid dynamic content. It is a server-side programming language exploited by developers to insert java code in HTML files.