The document discusses JSP application models and frameworks. It describes the Model 1 and Model 2 architectures. Model 1 uses scripting elements and is page-centric, while Model 2 follows the MVC pattern and is suitable for complex applications. The J2EE framework provides enterprise services and uses components like servlets, session beans, and entity beans. Exceptions can occur during translation or at request time, and unhandled exceptions are forwarded to an error page.
call girls in Vaishali (Ghaziabad) ๐ >เผ8448380779 ๐ genuine Escort Service ๐โ๏ธโ๏ธ
ย
1.jsp application models
1. JSP Application Models
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
2. Review
๏ฑ A JavaBean is a reusable software component that is manipulated in a
builder tool.
๏ฑ get() and set() methods are used with the property for which the data
has to be set.
๏ฑ The features of JavaBeans are methods, events, properties,
introspection and serialization.
๏ฑ JavaBeans have four scopes; page, request, session and application.
๏ฑ JAR is a compressed file containing the Java classes.
๏ฑ Every JavaBean is a Java class, but every Java class may not be a
JavaBean.
๏ฑ <jsp:useBean> tag is used for creating reference in any code.
๏ฑ The Bean tag provides the page a means to encapsulate business logic
separately from the content presentation.
๏ฑ The key components of JavaMail APIs are session, message and
transport.
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
3. JSP Application Models Overview
๏ฑ Consists of Java code, HTML codes, and JSP
tags
๏ฑ Two approaches for building JSP
applications are:
๏ง Model 1
๏ง Model 2
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
4. Model 1 Architecture
๏ฎ Represents a page-centric design
๏ฎ Developed using scripting elements, custom tags, and a
scripting language
๏ฎ Client request is directly processed by JSP page
๏ฎ JSP page accesses the database through JavaBeans to
generate a response
๏ฎ Model 1 applications are difficult to modify
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
5. Model 2 Architecture
๏ฑ Represents a controller design
๏ฑ Suitable for large and complex applications
๏ฑ Consists of a combination of servlets, JSP and JavaBeans
๏ฑ Based on Model-View-Controller (MVC) pattern
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
6. Model 2 Architecture (cont.)
๏ฑ The MVC pattern includes:
๏ง Model โ Represents the application object or data that serves
multiple views
๏ง View โ Represents the presentation component or the user
interface component of the data model
๏ง Controller โ Responds to the input in the user interface. The
controller transmits the request, and selects a view for presenting
data to the user.
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
7. Implementing Model 2 Architecture
๏ฑ Requires controller servlet, request handler, page beans and JSP
views
๏ฑ Controller servlet handles the incoming request, and forwards to the
request handler for further processing
๏ฑ The handleRequest() method of the RequestHandler
interface processes the request, and returns the URL of the JSP view
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
8. J2EE Framework
๏ฑ Provides enterprise services, such as transactions and security
๏ฑ Uses enterprise beans as a component
๏ฑ Enables low and high level data communication, design pattern, and a
component model that enables to build reusable components
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
9. J2EE Framework - Components
๏ฎ Servlet โ Consists of get() and post() methods, that are
used for requesting data in dynamic Web applications
๏ฎ Session bean โ Consist of temporary objects that enable to
distribute and isolate the processing task. The two forms of
shared data are:
๏ง Stateful
๏ง Stateless
๏ฎ Entity bean โ Represents the data items, such as rows in a
result set. The two forms of entity beans are:
๏ง Container managed persistence
๏ง Bean managed persistence
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
10. J2EE Framework โ Components (cont.)
๏ฎ Java terminologies โ Includes terminologies, such as Java
Naming and Directory Interface (JNDI), Enterprise JavaBeans
(EJB), servlets, JavaServer Pages (JSP), Extensible Markup
Language (XML) and Remote Method Invocation (RMI) that are
used in Web applications
๏ฎ Java Virtual Machine (JVM) โ Provides a consistent execution
platform for running Java codes
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
11. J2EE Framework - Benefits
๏ฎ Common application model โ Enables to create distributed,
reliable, scalable and secure Web applications
๏ฎ Generic infrastructure - Provides compatibility across vendors by
introducing a standard Application Program Interface (API)
๏ฎ Easy deployment and execution - Simplifies the task of deploying
and running the Web application
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
12. RequestDispatcher Interface
๏ฎ Forwards the request from a JSP page or a servlet to other resources
๏ฎ Other resources process the request and send a response to the client
๏ฎ The RequestDispatcher interface encapsulates the URL of a resource
๏ฎ Two methods of RequestDispatcher interface are:
๏ง Include()
๏ง Forward()
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
13. RequestDispatcher Interface Methods
Methods Syntax Description
include()
<jsp:include
page="localURL"
flush = "true")
Invokes one JSP page or
servlet from another
forward() <jsp:forward
page="Nextpage.
jsp"/>
Forwards a request from
one JSP page or servlet to
another
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
14. Includes page from
specified URL
Additional request
parameters
Transfers control
to specified URL
Additional request
parameters
Using Methods - Code Snippets
<jsp:include page="localURL" flush="true ">
<jsp:param name="parameterName1" value="parameterValue1"/>
//code
<jsp:param name="parameterName1" value="parameterValue1"/>
</jsp:include>
Using Include ()
<jsp:forward page="localURL ">
<jsp:param name="parameterName1" value="parameterValue1"/>
//code
<jsp:param name="parameterNameN" value="parameterValueN "/>
</jsp:forward>
Using Forward ()
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
15. Exception Handling
๏ง Exceptions are errors that can occur in a JSP page
๏ง The JSP page traps and handles request time errors
๏ง Unhandled exceptions are forwarded to the error page
๏ง Syntax
<%@ page errorPage=โerrorpage.jspโ %>
๏ง Set the isErrorPage attribute of page directive to true, to
make a JSP page an error handler
๏ง Syntax
<%@ page isErrorPage=โtrueโ %>
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
16. Exception Handling - Contโฆ
๏ฑ Translation time - Occurs when the JSP source file is converted to
servlets class file. The JSP engine handles translation time errors.
๏ฑ Request time - Occurs during the processing of the request. Request
time errors are the runtime errors that throw exceptions.
Makes JSP page an
error handler
Returns error
message
<html>
<body>
<%@ page isErrorPage="true" %>
Detected Error: <br>
<%= exception.getMessage() %>
</body>
</html>
Code Snippet to create an error page
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
17. Exception Handling - Contโฆ
<%@ page errorPage="errorpage.jsp" %>
<%
if (request.getParameter("param ").equals("value "))
{
// code
}
//The test above will throw a NullPointerException if param is
// not part of the query string. A better implementation is:
if ("value".equals(request.getParameter("param ")))
{
// code
}
%>
Forwards the unhandled
exception to
errorpage.jsp
Code Snippet to transfer control to the
error page
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
18. Summary
๏ฑ JSP technology enables the user to separate the presentation logic with the
programming logic
๏ฑ The user can make JSP page easy to read and maintain, by embedding
HTML or XML in the JSP page
๏ฑ Model 1 application is developed using scripting elements, custom tags,
and a scripting language, such as JavaScript
๏ฑ JSP page directly processes the request, and sends response to the client in
Model 1 architecture
๏ฑ The Model 2 applications are based on Model-View-Controller (MVC)
pattern:
๏ง Model
๏ง View
๏ง Controller
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
19. Summary โ Contโฆ
๏ง J2EE framework provides ready to use enterprise services, such as
transactions and security
๏ฑ The RequestDispatcher interface forwards the request from a JSP page or a
servlet to other resources, such as HTML file, servlet, or a JSP page
๏ฑ The two methods in RequesDispatcher interface are:
๏ง include()
๏ง forward()
๏ฑ The unhandled exceptions are forwarded to the error handler file
๏ฑ The errors in JSP page includes:
๏ง Translation time
๏ง Request time
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3
20. Q & A
ยฉFPT SOFTWARE โ TRAINING MATERIAL โ Internal use 04e-BM/NS/HDCV/FSOFT v2/3