CHAPTER 11 ADVANCED FILTERING TECHNIQUES (Web site counters) 435 The

CHAPTER 11 ADVANCED FILTERING TECHNIQUES 435 The FindProd JSP Page Let s start with a simple JSP page. Listing 11-1 shows FindProd.jsp, which you may recall from the previous chapter. This trivial JSP page is used to test the handling of JSP resources. Listing 11-1. FindProd.jsp

You have submitted as the ${param.DEPT} department!

This JSP page prints out a message containing the department name by using EL and expects the client to supply the DEPT parameter. In a new web application, we would control the client that calls FindProd.jspto ensure that it does supply the required parameter. (In Chapter 10, we did that by specifying the URL to be entered to access the resource.) The FindProd Servlet Now we ll simulate a legacy resource. Listing 11-2 shows a servlet named FindProd. This servlet simulates a legacy resource being accessed by a user. It s hard-coded to display the DEPT parameter (department information). We re going to assume that we ve had the opportunity to update the servlet to process this department information. However, we re also going to assume that the legacy clients are out of our control, so they can t be updated to provide the department information. Later, we ll create a filter that automatically provides this parameter even though the client system accessing the legacy resource doesn t know how to supply it. Save this code in the WEB-INFclasses directory. To compile the servlet, you ll need to add Tomcat s servlet-api.jar file to your CLASSPATH. Listing 11-2. FindProd.java package com.apress.projsp; import javax.servlet.http.*; import java.io.*; public class FindProd extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws java.io.IOException { res.setContentType(”text/html”); PrintWriter out = res.getWriter(); out.println(”“); out.println(”

You have called from the ” + req.getParameter(”DEPT”)); out.println(” department!

“); out.close(); } }
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply