PowerPoint 簡報

Download Report

Transcript PowerPoint 簡報

Understanding JavaServer
Pages
鄧姚文
[email protected]
Outline




2015/7/20
What is a JSP page?
Hello User
Servlet or JSP
JSP architecture models
2
什麼是 JSP?




A JSP page is a web page that contains Java
code along with the HTML tags.
When accessed by a client, the Java code within
the page is executed on the server side,
producing textual data.
This data, which is surrounded by HTML tags, is
sent as a normal HTML page to the client.
The client has no knowledge of the Java code.

2015/7/20
The code is replaced by the HTML generated by the
Java code before the page is sent to the client.
3
Server-side includes



2015/7/20
Embedding programming languages within
HTML
A dynamic web page consists of markup
language code as well as programming
language code
Instead of serving the page as is to the
clients, a server processes the programming
language code, replaces the code with the
data generated by the code, and then sends
the page to the client
4
Hello User



寫一個 JSP 網頁,向使用者問好
使用 Tomcat
使用 Eclipse


2015/7/20
HTML + servlet
HTML + JSP
5
Servlet OR JSP?

當程式邏輯多過畫面時,用 servlet




2015/7/20
資料庫
數學計算
授權檢查
當畫面設計多過程式邏輯時,用 JSP
6
JSP Architecture Models



2015/7/20
The Model 1 architecture
The Model 2 architecture
The difference between the two lies in the
way they handle the requests
7
The Model 1 architecture
2015/7/20
8
The Model 1 architecture





2015/7/20
the target of every request is a JSP page
there is no central component that controls
the workflow of the application
suitable for simple applications
embedding business logic using big chunks
of Java code into the JSP page
does not promote reusability of application
components
9
The Model 2 architecture
2015/7/20
10
The Model 2 architecture




2015/7/20
follows the Model-View-Controller (MVC)
design pattern
the targets of all the requests are servlets
that act as the controller for the application
the JSP pages form the view of the
application
separation of responsibilities: ease of
maintenance
11
SUMMARY



2015/7/20
In this chapter, we learned about the basics
of JavaServer Pages technology and
serverside includes
briefly compared JSP pages to servlets and
discussed when it is appropriate to use one
or the other
discussed the two JSP architectural models
and how they differ in their request-handling
process
12