1 / 8

Servlets Part 3

Learn how to use server-side includes (SSI) and servlet chaining in Web Logic to enhance your servlet applications. This tutorial covers session tracking, servlet-to-servlet communication, server-side includes, and applet-to-servlet interaction.

Download Presentation

Servlets Part 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ServletsPart 3

  2. Topics • Session Tracking • ServletToServletCommunication-Servlet Chaining • ServerSideIncludes • AppletToServlet

  3. Server-Side Includes and Request Forwarding • Server Side includes (SSI) allow you to embed servlet calls within an HTML document using <servlet> tag. • By convention, these documents should use the .shtml extension – indicating to the server that the HTML document includes SSI directives and should be passed to a specialized SSI servlet for processing. • This special servlet (called SSIncludesServlet in Java Web Server) parses the <servlet> tags. • When the <servlet> tag is included, the SSIncludesServlet loads the servlet specified by the <servlet> tag and includes the servler output in the HTML page returned to the client.

  4. Server-Side Includes and Request Forwarding Syntax of the servlet tag <servlet name=SERVLET_NAME code=CLASS_NAME codebase=CLASS_LOCATION_URL INIT_PARAM1=VALUE1 INIT_PARAM2=VALUE2 INIT_PARAM3=VALUEn > <param name=SERVLET_PARAM1 value=VALUE1> <param name=SERVLET_PARAM1 value=VALUE2> <param name=SERVLET_PARAM1 value=VALUEn> </servlet>

  5. Server-Side Includes and Request Forwarding HTML Page using SSI to add a header and a footer <HTML><HEAD><TITLE>Servlet API </TITLE></HEAD> <BODY> <servlet code=“Header_Servlet”</servlet> <P> Some of these servers support Java Servlet API Web Logic, IBM Visual Age.. <BR> <servlet code=“Footer_Servlet”</servlet> </BODY> </HTML>

  6. Servlet Chaining • Servlet chaining is the process of passing the output of one servlet to the input of another. • This feature is similar to piping in UNIX. • The client request is sent to the first servlet in the chain. • Once the request has been processed by the servlet, it passes it soutput to the next servlet in the chain. • This process continues through any number of servlets until the last servlet’s output is returned to the client. • Servlet chain configuration is server-specific.

  7. Applet To Servlet • A servlet can generate a page with parameter values set to be passed to the embedded applet. • Example: public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = new PrintWriter ( response.getOutputStream()); out.write("<HTML><HEAD><TITLE> HTML Manipulation Example</TITLE> </HEAD><BODY>"); out.write("This applet receives data from the server via its PARAM tag"); out.write("<applet code=\"SimpleApplet\" width=\“300\" height=\“200\">"); out.write("<param name=\"Data\" value=\""; ); out.write("\">"</APPLET></BODY></HTML>); out.close(); }

  8. Applet To Servlet • See files MemberServlet.java and MemberApplet.java

More Related