J2EE Lecture 1:Servlet and JSP Dr. Ming Qiu Xiamen University Software School mingqiu@xmu.edu.cn
1. Preliminary Topics What do Web Server and Client do? HTML and HTTP GET and POST URL What will Web Server not do ?
1.1 What do Web Server and Client do? Head First to Servlets and JSP, Chap 01 1.1 What do Web Server and Client do?
1.1.1 HTML and HTTP HTML- HyperText Markup Language Head First to Servlets and JSP, Chap 01 1.1.1 HTML and HTTP HTML- HyperText Markup Language Web Server often send the browser a set of instructions written in HTML. Tells the browser how to present the content to the user HTTP – HyperText Transport Protocol Allows for simple request and response conversation. The client sends an HTTP request. The Server answers with an HTTP response.
Head First to Servlets and JSP, Chap 01 1.1.1 HTML and HTTP
Head First to Servlets and JSP, Chap 01 1.1.2 GET and POST
1.1.3 Uniform Resource Locators Head First to Servlets and JSP, Chap 01 1.1.3 Uniform Resource Locators
Head First to Servlets and JSP, Chap 01 Type a URL The browser create an HTTP GET request The HTTP GET is sent to the server And generates an HTTP response The server finds the page The browser rends HTML The response is sent to the browser
1.2 What will Web Server alone not do? Head First to Servlets and JSP, Chap 01 1.2 What will Web Server alone not do? Dynamic Content Saving the Data on the Server
2. Servlets Introduction Interface Servlet and HttpServlet
2.1Introduction Servlets and Java Server Pages (JSP) Java How to Program, Fifth Edition, Chap 24 2.1Introduction Servlets and Java Server Pages (JSP) Request-response model Packages javax.servlet javax.servlet.http javax.servlet.jsp javax.servlet.tagext Form the Web tier of J2EE
2.1Introduction Servlets under control of a container Java How to Program, Fifth Edition, Chap 24 2.1Introduction Servlets under control of a container
2.1 Introduction Servlet Request/response mechanism Head First to Servlets and JSP, Chap 02 2.1 Introduction Servlet Request/response mechanism
2.1 Introduction What does the container do? Communications support Head First to Servlets and JSP, Chap 02 2.1 Introduction What does the container do? Communications support Lifecycle Management Multithread Support Declarative security JSP Support
2.1 Introduction How the Container handles a request Head First to Servlets and JSP, Chap 02 2.1 Introduction How the Container handles a request
Head First to Servlets and JSP, Chap 02 2.1 Introduction
Head First to Servlets and JSP, Chap 02 2.1 Introduction
Java How to Program, Fifth Edition, Chap 24
Java How to Program, Fifth Edition, Chap 24 2.1 Introduction
Java How to Program, Fifth Edition, Chap 24 2.1 Introduction
Java How to Program, Fifth Edition, Chap 24 2.1 Introduction
2.2 Interface Servlet and HttpServlet Java How to Program, Fifth Edition, Chap 24 2.2 Interface Servlet and HttpServlet Interface Servlet All servlets must implement this interface All methods of interface Servlet are invoked by servlet container GenericServlet and HttpServlet
2.2 Interface Servlet and HttpServlet Java How to Program, Fifth Edition, Chap 24 2.2 Interface Servlet and HttpServlet Overrides method service Two most common HTTP request types get requests post requests Method doGet responds to get requests Method doPost responds to post requests HttpServletRequest and HttpServletResponse objects
2.2 Interface Servlet and HttpServlet Java How to Program, Fifth Edition, Chap 24 2.2 Interface Servlet and HttpServlet HttpServletRequest Interface
2.2 Interface Servlet and HttpServlet Java How to Program, Fifth Edition, Chap 24 2.2 Interface Servlet and HttpServlet HttpServletResponse Interface
Handling HTTP get Requests Containing Data Java How to Program, Fifth Edition, Chap 24 Handling HTTP get Requests Containing Data
2.2 Interface Servlet and HttpServlet Java How to Program, Fifth Edition, Chap 24 2.2 Interface Servlet and HttpServlet
2.2 Interface Servlet and HttpServlet Java How to Program, Fifth Edition, Chap 24 2.2 Interface Servlet and HttpServlet
Handling HTTP post Requests Containing Data Java How to Program, Fifth Edition, Chap 24 Handling HTTP post Requests Containing Data
2.2 Interface Servlet and HttpServlet Java How to Program, Fifth Edition, Chap 24 2.2 Interface Servlet and HttpServlet
2.2 Interface Servlet and HttpServlet Java How to Program, Fifth Edition, Chap 24 2.2 Interface Servlet and HttpServlet
3. JSP JavaServer Pages Reuse existing Java components Java How to Program, Fifth Edition, Chap 25 3. JSP JavaServer Pages Extension of Servlet technology Reuse existing Java components Without programming Java Create custom tags Encapsulate complex functionality Classes and interfaces specific to JSP Package javax.servlet.jsp Package javax.servlet.jsp.tagext
Java How to Program, Fifth Edition, Chap 25 3. JSP
Java How to Program, Fifth Edition, Chap 25 3. JSP
3. JSP In the end, JSP is just a servlet Head First to Servlets and JSP, Chap 07 3. JSP In the end, JSP is just a servlet
3 JSP JSPs Servlets Used when content is mostly fixed-template data Java How to Program, Fifth Edition, Chap 25 3 JSP JSPs Used when content is mostly fixed-template data Small amounts of content generated dynamically Servlets Used when small amount of content is fixed-template data Most content generated dynamically
3. JSP Custom Tag Library JSP’s tag extension mechanism Java How to Program, Fifth Edition, Chap 25 3. JSP Custom Tag Library JSP’s tag extension mechanism Enables programmers to define new tags Tags encapsulate complex functionality, written in java code Keep java code out of the pages.