Download presentation
Presentation is loading. Please wait.
Published byChristal Warner Modified over 9 years ago
2
Advanced Java Session 6 New York University School of Continuing and Professional Studies
3
2 Objectives Java Servlets –BasicServlet –Accessing Form Data, HTTP Headers, CGI Variables –Cookies and Sessions Java Server Pages –Overview of Java Server Pages –Using Java Beans in JSP Integrating Java Servlets and JSP
4
3 Web Applications Architecture client Web server App server Backend Services such as db, quote server
5
4 Java Servlets Modern replacement for CGIs Server components written in Java Advantages of Servlets –Efficient –State Management –Portable –Robust –Extensible –Quick Development –Widespread Acceptance
6
5 Application Server Model services Servlet container servlets
7
6 Classes and Interfaces Servlet ServletConfig ServletContext GenericServlet ServletRequest ServletResponse HttpServlet HttpServletRequest HttpServletResponse HttpSession Cookie
8
7 GenericServlet Abstract class public void init() throws ServletException public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException public void destroy()
9
8 HttpServlet Abstract class protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
10
9 BasicServlet example tomcat env javac BasicServlet.java servit BasicServlet.class tomcat start http://localhost:8080/servlet/BasicServlet
11
10 Accessing Form Data String getParameter(String) Enumeration getParameterNames() ShowParameters.java
12
11 Accessing HTTP Headers String getMethod() String getRequestURI() String getProtocol() Enumeration getHeaderNames() ShowRequestHeader.java
13
12 Accessing CGI Variables String getAuthType() String getContentLength() String getContentType() ……. More complete list is in the handout. ShowCGIVariables.java
14
13 Generating Response setContentType() getWriter() …… More in the handout.
15
14 Handling Sessions Object getAttribute(String name) void setAttribute(String name, Object value) Enumeration getAttributeNames() void removeAttribute(String name) void Invalidate() ShowSession.java
16
15 Java Server Pages Use embedded java code in HTML files “automatically generated” servlet Part of the J2EE framework Supported by most Application Servers
17
16 Jsp Servlet Java Server Pages turn into a servlet Engine translates JSP into a java servlet, compiles it and executes it. HttpJspPage interface is a subclass of Servlet JSP engine provides a class that implements HttpJspPage interface _jspService method is the main entry point
18
17 Embedded Tags
19
18 Embedded Java code hello item number
20
19 <%@ page directives Language Import contentType errorPage Extends isErrorPage isThreadSafe Session autoFlush Buffer
21
20 Using Java Beans in Java Server Pages Basic Bean Use
22
21 Accessing Bean Properties <jsp:setProperty name=“book1” property=“title” value=“Developing Applications in J2EE”/>
23
22 Associating properties with HTML input parameters BookEntry example
24
23 Extending JSP with custom tags body text TagSupport class implements Tag BodyTagSupport class implements BodyTag Tag Library Descriptor
25
24 Integrating Servlets and Java Server Pages Use servlets for presentation logic User jsp for layout Jsp can also generate XML Examples: ShowPage.java ShowError.java
26
25 Thank you
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.