1 - WT - JSP Main
1 - WT - JSP Main
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING
Subject Name: Web Technology
Day: 29
Topics Covered: Server Side Scripts-JSP
1
Faculty Name: Dr. Avinash Dwivedi Programe Name: B.Tech (CSE,AI &ML)
Prerequisites, Objectives and Outcomes
• Index.jsp
<html>
<body>
<% out.print(2*5); %>
</body>
</html>
Output: It will print 10 on the browser.
Do I need to follow the directory structure to run a simple JSP?
• No, there is no need of directory structure if you don't have
class files or TLD files. For example, put JSP files in a folder
directly and deploy that folder. It will be running fine.
However, if you are using Bean class, Servlet or TLD file, the
directory structure is required.
• The Directory structure of JSP
JSP elements (overview)
• Writing a program in JSP is nothing but making use of various tags
which are available in JSP.
• In JSP we have three categories of tags; they are
• </body>
• </html>
• Index.jsp
<html>
<body>
<form action="welcome.jsp">
<input type="text" name="uname"><
br/>
<input type="submit" value="go">
</form>
</body>
</html>
File: welcome.jsp
<html>
<body>
<%= "Welcome "+request.getParameter("uname") %>
</body>
</html>
JSP Implicit Objects
• There are 9 jsp implicit objects. These objects
are created by the web container that are available to
all the jsp pages.
• The available implicit objects are out, request, config,
session, application etc.
• A list of the 9 implicit objects is given below:
9 implicit objects
These objects are created by the web container that are
available to all the jsp pages.
Object Type
out JspWriter
request HttpServletRequest
response HttpServletResponse
config ServletConfig
application ServletContext
session HttpSession
pageContext PageContext
page Object
exception Throwable
1) JSP out implicit object
index.html
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
welcome.jsp
<%
response.sendRedirect("http://www.google.com");
%>
errorPage isErrorPage exception JSP
• "errorPage" and "isErrorPage" are the two of 14
attributes supported by page directive.
• "errorPage"
• Any JSP file declared with errorPage, when generates
exceptions, can send the exceptions to another JSP file that is
declared with isErrorPage. errorPage attribute is used to
specify the address of another JSP file where isErrorPage is set
to true. errorPage and isErrorPage go together.
• Syntax: <%@ page errorPage="URL of other JSP file" %>
isErrorPage
• Any JSP file declared with isErrorPage (and set to a value of
true), is capable to receive exceptions from other JSP pages.
Implicit object exception is available to these pages only (set
with true). Default value is false.
• </body>
Config Implicit Object in JSP
• It is an instance of javax.servlet.ServletConfig. Config Implicit
object is used for getting configuration information for a
particular JSP page. Using application implicit object we can
get application-wide initialization parameters, however using
Config we can get initialization parameters of an individual
servlet mapping.
Methods of Config Implicit Object