Servlets Part 3 Topics Session Tracking Servlet To

  • Slides: 8
Download presentation
Servlets Part 3

Servlets Part 3

Topics • • Session Tracking Servlet. To. Servlet. Communication-Servlet Chaining Server. Side. Includes Applet.

Topics • • Session Tracking Servlet. To. Servlet. Communication-Servlet Chaining Server. Side. Includes Applet. To. Servlet

Server-Side Includes and Request Forwarding • Server Side includes (SSI) allow you to embed

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 SSIncludes. Servlet in Java Web Server) parses the <servlet> tags. • When the <servlet> tag is included, the SSIncludes. Servlet 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

Server-Side Includes and Request Forwarding Syntax of the servlet tag <servlet name=SERVLET_NAME code=CLASS_NAME codebase=CLASS_LOCATION_URL INIT_PARAM 1=VALUE 1 INIT_PARAM 2=VALUE 2 INIT_PARAM 3=VALUEn > <param name=SERVLET_PARAM 1 value=VALUE 1> <param name=SERVLET_PARAM 1 value=VALUE 2> <param name=SERVLET_PARAM 1 value=VALUEn> </servlet>

Server-Side Includes and Request Forwarding HTML Page using SSI to add a header and

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 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

Applet To Servlet • • A servlet can generate a page with parameter values set to be passed to the embedded applet. Example: public void do. Get(Http. Servlet. Request request, Http. Servlet. Response response) throws Servlet. Exception, IOException { response. set. Content. Type("text/html"); Print. Writer out = new Print. Writer ( response. get. Output. Stream()); 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="Simple. Applet" width=“ 300" height=“ 200">"); out. write("<param name="Data" value=""; ); out. write("">"</APPLET></BODY></HTML>); out. close(); }

Applet To Servlet • See files Member. Servlet. java and Member. Applet. java

Applet To Servlet • See files Member. Servlet. java and Member. Applet. java