Java Servlet & JSP Cookbook
Problem
You have already precompiled a JSP and want to specify a mapping to the JSP page implementation class in your deployment descriptor. Solution
Cut and paste the servlet and servlet-mapping elements generated automatically by JspC into web.xml . Create the proper package- related directories in the WEB-INF/classes directory of your web application, then place the precompiled JSPs into that directory. Discussion
Precompiling JSPs allows you to remove the JSP page syntax files from your web application and just use the resulting servlet class files. You can then use the servlet-mapping element in web.xml to map a JSP-style URL (e.g., default.jsp ) to the compiled servlet class. Here is how to accomplish this task:
When the web users request the URL specified by the servlet-mapping for that JSP page implementation class, the web container will now direct that request to the mapped servlet class. Example 5-8 shows a servlet configuration for a precompiled JSP. Example 5-8. A web.xml entry for a precompiled JSP
<servlet> <servlet-name>org.apache.jsp.precomp_jsp</servlet-name> <servlet-class>org.apache.jsp.precomp_jsp</servlet-class> </servlet> <servlet-mapping> <servlet-name>org.apache.jsp.precomp_jsp</servlet-name> <url-pattern>/precomp.jsp</url-pattern> </servlet-mapping> The directory structure for this class in your web application should be something like: /WEB-INF/classes/org/apache/jsp/precomp_jsp.class . If the context path for your web application is /home , users can request this JSP's implementation class (a servlet, behind the scenes) with a URL similar to http://localhost:8080/home/precomp.jsp . See Also
Recipe 5.1-Recipe 5.3; Chapter JSP.11.4 of the JSP 2.0 specification. |