Академический Документы
Профессиональный Документы
Культура Документы
Module 2
Module 2
• JSP and HTTP, JSP Engines, How JSP Works, JSP
and Servlet, Anatomy of a JSP Page
• JSP Syntax, JSP Directives, JSP implicit objects
• JSP form processing, JSP actions
• Sharing Data Between JSP Pages Requests and
Users: Users Passing Control and Data
between Pages
• Sharing Session and Application Data
Advantages of JSP over Servlet
1. Reduced Coding: The objects of PrintWriter, ServletConfig, ServletContext,
HttpSession and RequestDispatcher etc. are created by the Programmer in
Servlets and used. But in JSP, they are builtin and are known as "implicit
objects". That is, in JSP, Programmer never creates these objects and
straightaway use them as they are implicitly created and given by JSP
container. This decreases lot of coding.
2. JSP needs no compilation by the Programmer. Programmer deploys directly a
JSP source code file in server where as incase of Servlets, the Programmer
compiles manually a Servlet file and deploys a .class file in server.
3. With JSP, Programmer can build custom tags that can be called in JavaBeans
directly. Servlets do not have this advantage. Reusability increases with tag
libraries and JavaBean etc.
4. Presentation logic: In Servlets, both static code and dynamic code are put
together. In JSP, they are separated.
3
The JSP Framework
• Idea:
– Java Server Pages (JSP) is a server-side programming technology.
– Servlet adds HTML code inside Java code, while JSP adds Java code
inside HTML using JSP tags. Everything a Servlet can do, a JSP page can
also do it.
– A JSP page consists of HTML tags and JSP tags(to insert java code in
HTML pages). The JSP tags which allow java code to be included into it
are <% ----java code----%>
– It can consist of either HTML or XML (combination of both is also
possible) with JSP actions and commands.
• Uses
– Used to design forms and registration pages with the dynamic content.
– to access JavaBeans objects.
– share information across pages using request and response objects.
4
JSP
• JSP is a server side technology that does all the processing at
server. It is used for creating dynamic web applications, using
java as programming language.
Hello.jsp
Read
Request
helloServlet.java
Generate
Response
Client Server
Execute
helloServlet.class
Processing phase
14
How JSP Works
How JSP works: JSP Processing
How JSP works:JSP Processing
JSP - Lifecycle
JSP - Lifecycle
JSP - Syntax
JSP - Syntax
JSP Directives
• These directives provide directions and
instructions to the container, telling it how to
handle certain aspects of the JSP processing.
• The session Object
• The session object is an instance
of javax.servlet.http.HttpSession and behaves
exactly the same way that session objects
behave under Java Servlets.
• The session object is used to track client
session between client requests.