Download presentation
Presentation is loading. Please wait.
Published byZsuzsanna Lili Dudás Modified over 5 years ago
1
Introduction to JSP Dept. of B.Voc Software Development and System Administration St. Joseph’s College(Autonomous) Trichy-02 By Dr. J. Ronald Martin Introduction to JSP : Dept. of B.Voc SD&SA
2
Introduction to JSP : Dept. of B.Voc SD&SA
JSP (Java Server Pages) is server side technology to create dynamic java web application. JSP can be thought as an extension to servlet technology because it provides features to easily create user views. JSP Page consists of HTML code and provide option to include java code for dynamic content. Introduction to JSP : Dept. of B.Voc SD&SA
3
Introduction to JSP : Dept. of B.Voc SD&SA
Since web applications contain a lot of user screens, JSPs are used a lot in web applications. To bridge the gap between java code and HTML in JSP, it provides additional features such as JSP Tags, Expression Language, Custom tags. This makes it easy to understand and helps a web developer to quickly develop JSP pages. Introduction to JSP : Dept. of B.Voc SD&SA
4
Introduction to JSP : Dept. of B.Voc SD&SA
JSP Declaration Tag The JSP declaration tag is used to declare fields and methods. <html> <body> <%! int data=50; %> <%= "Value of the variable is:"+data %> </body> </html> Introduction to JSP : Dept. of B.Voc SD&SA
5
Introduction to JSP : Dept. of B.Voc SD&SA
JSP Scriptlet tag In JSP, java code can be written inside the jsp page using the scriptlet tag. <html> <body> <% out.print("welcome to jsp"); %> </body> </html> JSP expression tag The code placed within JSP expression tag is written to the output stream of the response. <html> <body> <%= "welcome to jsp" %> </body> </html> Introduction to JSP : Dept. of B.Voc SD&SA
6
Introduction to JSP : Dept. of B.Voc SD&SA
Page Directive There are several attributes, which are used along with Page Directives and these are import session isErrorPage errorPage ContentType isThreadSafe extends info language autoflush Buffer Introduction to JSP : Dept. of B.Voc SD&SA
7
Introduction to JSP : Dept. of B.Voc SD&SA
import="java.io.*%> import="java.lang.*%> <%--Comment: OR Below Statement: Both are Same--%> import="java.io.*, java.lang.*"%> Introduction to JSP : Dept. of B.Voc SD&SA
8
Introduction to JSP : Dept. of B.Voc SD&SA
page errorPage="ExceptionHandling.jsp"%> This means if any exception occurs on the JSP page where this code has been placed, the ExceptionHandling.jsp (this page should have isErrorPage true) page needs to be called. Introduction to JSP : Dept. of B.Voc SD&SA
9
Introduction to JSP : Dept. of B.Voc SD&SA
JSP implicit object Implicit Object Description request The HttpServletRequest object associated with the request. response The HttpServletRequest object associated with the response that is sent back to the browser. out The JspWriter object associated with the output stream of the response. session The HttpSession object associated with the session for the given user of request. application The ServletContext object for the web application. config The ServletConfig object associated with the servlet for current JSP page. pageContext The PageContext object that encapsulates the enviroment of a single request for this current JSP page page The page variable is equivalent to this variable of Java programming language. exception The exception object represents the Throwable object that was thrown by some other JSP page. Introduction to JSP : Dept. of B.Voc SD&SA
10
Introduction to JSP : Dept. of B.Voc SD&SA
JSP Action JSP actions use the construct in XML syntax to control the behavior of the servlet engine. can dynamically insert a file, reuse the beans components, forward user to another page, etc. through JSP Actions like include and forward. Unlike directives, actions are re-evaluated each time the page is accessed. Syntax: <jsp:action_name attribute="value" /> Introduction to JSP : Dept. of B.Voc SD&SA
11
Introduction to JSP : Dept. of B.Voc SD&SA
There are 11 types of action names as following: jsp:useBean jsp:include jsp:setProperty jsp:getProperty jsp:forward jsp:plugin jsp:attribute jsp:body jsp:text jsp:param jsp:output Introduction to JSP : Dept. of B.Voc SD&SA
12
Introduction to JSP : Dept. of B.Voc SD&SA
Action Tag Description jsp:forward forward the request to a new page Usage : <jsp:forward page="Relative URL" /> jsp:useBean instantiates a JavaBean Usage : <jsp:useBean id="beanId" /> jsp:getProperty retrieves a property from a JavaBean instance. Usage : <jsp:useBean id="beanId" ... /> ... <jsp:getProperty name="beanId" property="someProperty" .../> Where, beanName is the name of pre-defined bean whose property we want to access. Introduction to JSP : Dept. of B.Voc SD&SA
13
Introduction to JSP : Dept. of B.Voc SD&SA
jsp:setProperty store data in property of any JavaBeans instance. Usage : <jsp:useBean id="beanId" ... /> ... <jsp:setProperty name="beanId" property="someProperty" value="some value"/> Where, beanName is the name of pre-defined bean whose property we want to access. jsp:include includes the runtime response of a JSP page into the current page. jsp:plugin Generates client browser-specific construct that makes an OBJECT or EMBED tag for the Java Applets Introduction to JSP : Dept. of B.Voc SD&SA
14
Introduction to JSP : Dept. of B.Voc SD&SA
jsp:fallback Supplies alternate text if java plugin is unavailable on the client. You can print a message using this, if the included jsp plugin is not loaded. jsp:element Defines XML elements dynamically jsp:attribute defines dynamically defined XML element's attribute jsp:body Used within standard or custom tags to supply the tag body. jsp:param Adds parameters to the request object. jsp:text Used to write template text in JSP pages and documents. Usage : <jsp:text>Template data</jsp:text> Introduction to JSP : Dept. of B.Voc SD&SA
15
Introduction to JSP : Dept. of B.Voc SD&SA
welcome.jsp <html> <head> <title>Welcome Page</title> </head> <body> include file="header.jsp" %> Welcome, User </body> </html> header.jsp <img src="header.jpg" alt="This is Header image" / > Introduction to JSP : Dept. of B.Voc SD&SA
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.