SlideShare a Scribd company logo
Servlet and JSP
Gary
07/24/2013
Question
• Blocking I/O如何處理多個read?
• I/O
– Blocking I/O
– Non-blocking I/O
– Asynchronous I/O
– Synchronous I/O
Question
• Blocking I/O model
recvfrom
application
System call
Process
datagram
Process blocks in
call to recvfrom
Wait for data
Copy data from
kernel to user
No datagram
ready
Datagram ready
Copy datagram
Copy complete
Return OK
kernel
Question
• Non-Blocking I/O model
recvfrom
application
System call
Process
datagram
Process repeatedly
calls recvfrom
waiting for an OK
return(polling)
Wait for data
Copy data from
kernel to user
No datagram
ready
Datagram ready
Copy datagram
Copy complete
Return OK
kernel
EWOULDBLOCK
recvfrom
System call No datagram
readyEWOULDBLOCK
Question
• Asynchronous I/O model
recvfrom
application
System call
Signal handler
process
datagram
Process continues
executing
Wait for data
Copy data from
kernel to user
No datagram
ready
Datagram ready
Copy datagram
Copy complete
Deliver signal
specofied in recvfrom
kernel
return
Question
• Synchronous I/O
• Definition
– A synchronous I/O operation causes the
requesting process to be blocked until that I/O
operation completes.
Question
• How to solve multiple I/O devices?
• Use select()
A
B
A
Select()
device
Question
• 手動讓process休眠
DEFINE_WAIT(my_wqentry);
初始化一個待命佇列項目
void prepare_to_wait(wait_queue_head_t *queue, wait_queue_t *my_wqentry, int state);
將待命佇列項目加進佇列
prepare_to_wait();
可以開始休眠
schedule();
重新加入排程
void finish_wait(wait_queue_head_t *queue, wait_queue_t *my_wqentry);
把柱列項目清除
Question
• Asynchronous Notification
– 當新資料進來時獲得通知
– 執行優先度低,無法使用輪詢
fcntl(STDIN_FILENO, F_SETOWN, getpid());
讓核心知道通知對象是誰
fcntl(STDIN_FILENO, FSETFL, oflags | FASYNC);
啟動臨時通知
Question
• 同時存取database
– Locking
– Timestamp
– Multiversion concurrency control
Outline
• Introduction
• CGI
• Servlet
• Implement of Servlet
• JSP
• Conclusion
Introduction
• You can use JSP or servlet to solve dynamic
web page needs. JSP is web page design
oriented, and servlet is program designed
oriented. Knowing their character can
cooperate two expertise and make the
achievement better.
CGI
• Common Gateway Interface
• A standard method for web server software to
delegate the generation of web content to
executable files.
• Web server send request to external program,
and the program response with static file.
CGI
Web Server
CGI Program Database
Web Browser
1. Request
2. Input data
3. May access database
4. Response as HTML doc
Figure: CGI workflow
CGI
• CGI can designed as any computer language.
Perl is the most popular.
• When server receive a request, it produce a
new process to execute CGI program.
• Consume many memory.
• Each CGI program is isolated.
Servlet
• In order to solve the disadvantage of CGI,
servlet is developed.
• Servlet is designed to substitute CGI.
• The word servlet is composed of “server” and
“let”. In Java, “let” means small application.
• Servlet is run in server side, and applet is run
in client side.
Servlet
Client Browser Web Server
Servlet Container
Servlet
1. Browser
requests page
2. Web server
delegates to container
3. Container executes servlet,
creating instance if required
4. Servlet executes,
generates response
5. Server
returns response
Figure: Servlet workflow
Servlet
• Web container
– Execute JSP and servlet.
– Like Java only recognizes JVM, servlet/JSP only
recognizes web container.
– Parsing HTTP request, create instance like
HttpServletRequest、 HttpServletResponse、
HttpSession
Servlet
• Servlet life cycle
– void init()
• When servlet is first loaded, initialize servlet status
– void service()
• Serve a request. Can be called multiple times.
– void destroy()
• Dispose servlet.
Servlet
• Since the output of servlet is HTML, the usage
of servlets doesn’t constrain by browser.
• No matter how many requests, only one
servlet will be loaded into JVM.
• When there is a request, there is a thread, not
process.
• Servlets is persistent until be deystroyed.
Implement of Servlet
• Environment – oracle java jdk 1.7.0
• Add path to environment variables
– JAVA_HOME
– PATH
– CLASSPATH
Implement of Servlet
• Download Apache-Tomcat-7.0.42
• Use tomcat as web server and web container
Implement of Servlet
Implement of Servlet
• javax.servlet
– The javax.servlet package contains a number of
classes and interfaces that describe and define the
contracts between a servlet class and the runtime
environment provided for an instance of such a
class by a conforming servlet container
Implement of Servlet
• javax.servlet.http
– The javax.servlet.http package contains a number
of classes and interfaces that describe and define
the contracts between a servlet class running
under the HTTP protocol and the runtime
environment provided for an instance of such a
class by a conforming servlet container.
Implement of Servlet
• javax.servlet
Implement of Servlet
• javax.servlet.http
Implement of Servlet
• service() can handle doGet() and doPost()
• Get
– The request parameter shows on URL
– Not proper for password
– Not too long data
– Good for setting as tags or bookmarks
– Don’t change the status of server
Implement of Servlet
• Post
– The request parameter is in Body
– Good for password
– Good for long data
– Not proper for tags or bookmarks
– May change content of database
Implement of Servlet
• HttpServletRequest
– The object of client sending request to server
– E.g. Form input data
• HttpServletResponse
– The object of server responding to client
– E.g. Show HTML doc on browser
Implement of Servlet
• HttpServletResponseObjectName.setContentType(“ContentType”)
• E.g. res.serContentTyoe(“text/html;charset=Big5”)
Implement of Servlet
• In order to show information on web page,
use HttpServletResponse object create a
PrintWriter object.
• And use PrintWriter to write HTML tags.
Implement of Servlet
• Write web.xml
• /WEB-INF/
/classes/
| |HelloServlet.class
|web.xml
Implement of Servlet
• Web.xml
– Used to configure welcome page、 servlet 、
filter
– Run before load servlet
url-pattern
servlet-name
servlet-class
Implement of Servlet
• The result
JSP
• HelloWorld.java
JSP
• HelloWorld.jsp
• A JSP page is basically a web page with
traditional HTML and bits of Java code.
JSP
Figure: JSP workflow
JSP
• When a JSP file is accessed, the container
converts it into a Java class that implements
the javax.servlet.jsp.HttpJspPage interface.
The various JSP building blocks are translated
into Java code and compiled into a Servlet.
JSP
• The element of JSP can be divided into three
kinds
– Directive
• Definite the static information of web page.
– Action
• Send data according to the request of client.
– Scripting
• Small piece of java code. Only execute if client request.
JSP
directive
action
scripting
JSP
• Implicit object
• Corresponds to an object in servlet
• out
– corresponds to JspWriter, which associates
PrintWriter
• Request
– corresponds to HttpServletRequest
• Response
– corresponds to HttpServletResponse
JSP
Conclusion
• Deal with JSP is easier than with servlet.
• Knowing how to write JSP code is helpful in
developing server-side web design.

More Related Content

What's hot

Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packagesvamsi krishna
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
Tanmoy Barman
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
Ankit Minocha
 
Servlets
ServletsServlets
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servlets
JavaEE Trainers
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
KushagraChadha1
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
Dhruvin Nakrani
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
Mazenetsolution
 
Servlets
ServletsServlets
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
BG Java EE Course
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
JavaEE Trainers
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
Chitrank Dixit
 
Jsp servlets
Jsp servletsJsp servlets
Jsp servlets
Rajavel Dhandabani
 

What's hot (20)

Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packages
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Servlets
ServletsServlets
Servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
 
Servlets
ServletsServlets
Servlets
 
JDBC in Servlets
JDBC in ServletsJDBC in Servlets
JDBC in Servlets
 
Servlets
ServletsServlets
Servlets
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
 
Servlets
ServletsServlets
Servlets
 
Jsp servlets
Jsp servletsJsp servlets
Jsp servlets
 
Servlets
ServletsServlets
Servlets
 

Similar to Servlet and JSP

Servlets
ServletsServlets
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
deepak kumar
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Tushar B Kute
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
MouDhara1
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
kstalin2
 
Servlet1.ppt
Servlet1.pptServlet1.ppt
Servlet1.ppt
KhushalChoudhary14
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
sindhu991994
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
pkaviya
 
Servlets Java Slides & Presentation
Servlets Java Slides & Presentation Servlets Java Slides & Presentation
Servlets Java Slides & Presentation
Anas Sa
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
Fahad Golra
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
karthiksmart21
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
team11vgnt
 

Similar to Servlet and JSP (20)

Servlets
ServletsServlets
Servlets
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet1.ppt
Servlet1.pptServlet1.ppt
Servlet1.ppt
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
 
19servlets
19servlets19servlets
19servlets
 
Servlets
ServletsServlets
Servlets
 
Servlets Java Slides & Presentation
Servlets Java Slides & Presentation Servlets Java Slides & Presentation
Servlets Java Slides & Presentation
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 

More from Gary Yeh

Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
Gary Yeh
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
Gary Yeh
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
Gary Yeh
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
Gary Yeh
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
Gary Yeh
 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScript
Gary Yeh
 
JQuery mobile
JQuery mobileJQuery mobile
JQuery mobile
Gary Yeh
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
Gary Yeh
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
Gary Yeh
 
Git Workflow
Git WorkflowGit Workflow
Git Workflow
Gary Yeh
 

More from Gary Yeh (10)

Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScript
 
JQuery mobile
JQuery mobileJQuery mobile
JQuery mobile
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
Git Workflow
Git WorkflowGit Workflow
Git Workflow
 

Recently uploaded

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 

Recently uploaded (20)

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 

Servlet and JSP

  • 2. Question • Blocking I/O如何處理多個read? • I/O – Blocking I/O – Non-blocking I/O – Asynchronous I/O – Synchronous I/O
  • 3. Question • Blocking I/O model recvfrom application System call Process datagram Process blocks in call to recvfrom Wait for data Copy data from kernel to user No datagram ready Datagram ready Copy datagram Copy complete Return OK kernel
  • 4. Question • Non-Blocking I/O model recvfrom application System call Process datagram Process repeatedly calls recvfrom waiting for an OK return(polling) Wait for data Copy data from kernel to user No datagram ready Datagram ready Copy datagram Copy complete Return OK kernel EWOULDBLOCK recvfrom System call No datagram readyEWOULDBLOCK
  • 5. Question • Asynchronous I/O model recvfrom application System call Signal handler process datagram Process continues executing Wait for data Copy data from kernel to user No datagram ready Datagram ready Copy datagram Copy complete Deliver signal specofied in recvfrom kernel return
  • 6. Question • Synchronous I/O • Definition – A synchronous I/O operation causes the requesting process to be blocked until that I/O operation completes.
  • 7. Question • How to solve multiple I/O devices? • Use select() A B A Select() device
  • 8. Question • 手動讓process休眠 DEFINE_WAIT(my_wqentry); 初始化一個待命佇列項目 void prepare_to_wait(wait_queue_head_t *queue, wait_queue_t *my_wqentry, int state); 將待命佇列項目加進佇列 prepare_to_wait(); 可以開始休眠 schedule(); 重新加入排程 void finish_wait(wait_queue_head_t *queue, wait_queue_t *my_wqentry); 把柱列項目清除
  • 9. Question • Asynchronous Notification – 當新資料進來時獲得通知 – 執行優先度低,無法使用輪詢 fcntl(STDIN_FILENO, F_SETOWN, getpid()); 讓核心知道通知對象是誰 fcntl(STDIN_FILENO, FSETFL, oflags | FASYNC); 啟動臨時通知
  • 10. Question • 同時存取database – Locking – Timestamp – Multiversion concurrency control
  • 11. Outline • Introduction • CGI • Servlet • Implement of Servlet • JSP • Conclusion
  • 12. Introduction • You can use JSP or servlet to solve dynamic web page needs. JSP is web page design oriented, and servlet is program designed oriented. Knowing their character can cooperate two expertise and make the achievement better.
  • 13. CGI • Common Gateway Interface • A standard method for web server software to delegate the generation of web content to executable files. • Web server send request to external program, and the program response with static file.
  • 14. CGI Web Server CGI Program Database Web Browser 1. Request 2. Input data 3. May access database 4. Response as HTML doc Figure: CGI workflow
  • 15. CGI • CGI can designed as any computer language. Perl is the most popular. • When server receive a request, it produce a new process to execute CGI program. • Consume many memory. • Each CGI program is isolated.
  • 16. Servlet • In order to solve the disadvantage of CGI, servlet is developed. • Servlet is designed to substitute CGI. • The word servlet is composed of “server” and “let”. In Java, “let” means small application. • Servlet is run in server side, and applet is run in client side.
  • 17. Servlet Client Browser Web Server Servlet Container Servlet 1. Browser requests page 2. Web server delegates to container 3. Container executes servlet, creating instance if required 4. Servlet executes, generates response 5. Server returns response Figure: Servlet workflow
  • 18. Servlet • Web container – Execute JSP and servlet. – Like Java only recognizes JVM, servlet/JSP only recognizes web container. – Parsing HTTP request, create instance like HttpServletRequest、 HttpServletResponse、 HttpSession
  • 19. Servlet • Servlet life cycle – void init() • When servlet is first loaded, initialize servlet status – void service() • Serve a request. Can be called multiple times. – void destroy() • Dispose servlet.
  • 20. Servlet • Since the output of servlet is HTML, the usage of servlets doesn’t constrain by browser. • No matter how many requests, only one servlet will be loaded into JVM. • When there is a request, there is a thread, not process. • Servlets is persistent until be deystroyed.
  • 21. Implement of Servlet • Environment – oracle java jdk 1.7.0 • Add path to environment variables – JAVA_HOME – PATH – CLASSPATH
  • 22. Implement of Servlet • Download Apache-Tomcat-7.0.42 • Use tomcat as web server and web container
  • 24. Implement of Servlet • javax.servlet – The javax.servlet package contains a number of classes and interfaces that describe and define the contracts between a servlet class and the runtime environment provided for an instance of such a class by a conforming servlet container
  • 25. Implement of Servlet • javax.servlet.http – The javax.servlet.http package contains a number of classes and interfaces that describe and define the contracts between a servlet class running under the HTTP protocol and the runtime environment provided for an instance of such a class by a conforming servlet container.
  • 26. Implement of Servlet • javax.servlet
  • 27. Implement of Servlet • javax.servlet.http
  • 28. Implement of Servlet • service() can handle doGet() and doPost() • Get – The request parameter shows on URL – Not proper for password – Not too long data – Good for setting as tags or bookmarks – Don’t change the status of server
  • 29. Implement of Servlet • Post – The request parameter is in Body – Good for password – Good for long data – Not proper for tags or bookmarks – May change content of database
  • 30. Implement of Servlet • HttpServletRequest – The object of client sending request to server – E.g. Form input data • HttpServletResponse – The object of server responding to client – E.g. Show HTML doc on browser
  • 31. Implement of Servlet • HttpServletResponseObjectName.setContentType(“ContentType”) • E.g. res.serContentTyoe(“text/html;charset=Big5”)
  • 32. Implement of Servlet • In order to show information on web page, use HttpServletResponse object create a PrintWriter object. • And use PrintWriter to write HTML tags.
  • 33. Implement of Servlet • Write web.xml • /WEB-INF/ /classes/ | |HelloServlet.class |web.xml
  • 34. Implement of Servlet • Web.xml – Used to configure welcome page、 servlet 、 filter – Run before load servlet url-pattern servlet-name servlet-class
  • 37. JSP • HelloWorld.jsp • A JSP page is basically a web page with traditional HTML and bits of Java code.
  • 39. JSP • When a JSP file is accessed, the container converts it into a Java class that implements the javax.servlet.jsp.HttpJspPage interface. The various JSP building blocks are translated into Java code and compiled into a Servlet.
  • 40. JSP • The element of JSP can be divided into three kinds – Directive • Definite the static information of web page. – Action • Send data according to the request of client. – Scripting • Small piece of java code. Only execute if client request.
  • 42. JSP • Implicit object • Corresponds to an object in servlet • out – corresponds to JspWriter, which associates PrintWriter • Request – corresponds to HttpServletRequest • Response – corresponds to HttpServletResponse
  • 43. JSP
  • 44. Conclusion • Deal with JSP is easier than with servlet. • Knowing how to write JSP code is helpful in developing server-side web design.