SlideShare a Scribd company logo
1 of 44
Download to read offline
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 (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

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 KuteTushar B Kute
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.pptkstalin2
 
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
 
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 Connectivitypkaviya
 
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: ServletsFahad Golra
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxkarthiksmart21
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 

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
 
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
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 

More from Gary Yeh

Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGLGary 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.jsGary 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 EngineGary Yeh
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device DriverGary Yeh
 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScriptGary Yeh
 
JQuery mobile
JQuery mobileJQuery mobile
JQuery mobileGary Yeh
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database ConnectivityGary Yeh
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
Git Workflow
Git WorkflowGit Workflow
Git WorkflowGary 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

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 

Recently uploaded (20)

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 

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.