{ doGet( request, response ) ; }} The above servlet is as bare bones as it gets. It is important to note that you do not have to override the doGet or doPost methods if you instead override the service method and handle all requests there. This would not be considered good form in servlet design, but it is an option. In the next section we will see that a minimal JSP-generated servlet is a bit different since the doGet and doPost methods do not exist. Writing a Minimal JSP-Generated Servlet The nuts and bolts of a JSP-generated servlet are dependent on the JSP-to-servlet translator used with a particular Web server. Listing 8-2 shows a rather simple JSP page in which Tomcat 3.2 generated the servlet. However, this page is not the simplest because it has actual JSP scripting elements a simple page would have nothing but static text. Listing 8-2: A simple JSP page with a couple of scripting elements Minimal JSP Page

<%! String hello = "Hello World"; %> <%= hello %> Listing 8-3 shows the servlet that Tomcat generates from the JSP page in Listing 8-2. Listing 8-3: JSP-generated servlet for minimal JSP page in Listing 8-2 package jsp.loutest; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.PrintWriter; import java.io.IOException; import java.io.FileInputStream; import java.io.ObjectInputStream; import java.util.Vector; import org.apache.jasper.runtime.*; import java.beans.*; import org.apache.jasper.JasperException; public class _0002fjsp_0002floutest_0002floutest_0002ejsploutest_jsp_7extends HttpJspBase { /* begin [file=”D:\tomcat32\Webapps\examples\jsp\loutest\loutest.jsp”;from=(7,3);to=(7,34)] */ String hello = “Hello World”; // end static { } public _0002fjsp_0002floutest_0002floutest_0002ejsploutest_jsp_7( ) { } private static boolean _jspx_inited = false; public final void _jspx_init() throws JasperException { } public void _jspService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { JspFactory _jspxFactory = null; PageContext pageContext = null;
We specialize in RedHat Linux Apache web server technology for site owners and site developers and all our hosting packages come with a wide range of features as standard including automatic backups, visitor statistics, spam filtering, email anti virus and much more. Web Hosting Apache.Try us out!

Leave a Reply