80 likes | 92 Views
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.
E N D
Topics • Session Tracking • ServletToServletCommunication-Servlet Chaining • ServerSideIncludes • AppletToServlet
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.
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>
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>
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.
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(); }
Applet To Servlet • See files MemberServlet.java and MemberApplet.java