Hello,

I described a problem yesterday in which I could not get a JSP page to run
through a filter servlet.  To recap, I am trying to apply a filter to the
output of a JSP using a servlet chain. It seems that the JSP is being
processed properly, but is not subsequently run through the filter of the
servlet I have defined.

To illustrate, I have created a very dumbed-down example of the problem.

I have created a filter servlet called "BlinkFilter". This filter takes each
line from input and applies the <blink> tag on both ends of each line.

I have also created a jsp and a servlet that produce identical output (your
basic "hello world" html):
- hello.bjsp: a JSP
- Hello.java: a Servlet

In my web.xml, I have mapped the following URLs:
- *.bjsp: mapped to "jsp,BlinkFilter"
- /blink/Hello: mapped to "Hello,BlinkFilter"

I have attached the output for hello.bjsp and /blink/Hello. Notice that the
BlinkFilter servlet IS applied when running /blink/Hello, but IS NOT applied
when running hello.bjsp.

I include all relevant source and output files below:

-  hello.bjsp source
-  Hello.java source file
-  BlinkFilter.java source file
-  Output of hello.bjsp (NOTE: it is NOT run through the BlinkFilter
servlet)
-  Output of Hello servlet (NOTE: it is run through the BlinkFilter servlet)
-  The relevant portion of my web.xml, defining mappings of *.bjsp and
/blink/Hello

Any input is appreciated.

Thanks,

Brian Felder


----- Source of hello.bjsp: -----

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
        <title>Untitled</title>
</head>
<body>
Hello world!
</body>
</html>

----- End of output of hello.bjsp -----

----- Source of Hello.java -----

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Hello extends HttpServlet {

   public void doGet (
   //public void doGet (
      HttpServletRequest req,
      HttpServletResponse res
      ) throws ServletException, IOException
   {
      PrintWriter out = res.getWriter();
      out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0
Transitional//EN\">");
      out.println("<html>");
      out.println("<head>");
      out.println("     <title>Untitled</title>");
      out.println("</head>");
      out.println("<body>");
      out.println("Hello world!");
      out.println("</body>");
      out.println("</html>");
      out.close();
   }
}

----- End of source of Hello.java -----

----- Source of BlinkFilter.java ----- 

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BlinkFilter extends HttpServlet {

   /**
    * Initialize global variables
    */
   public void init(ServletConfig config) throws ServletException {
      super.init(config);
   }

   /**
    * Process the HTTP Get request
    */
   public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
      response.setContentType("text/html");
                PrintWriter out = response.getWriter();
      BufferedReader in = request.getReader();

      String line = null;
      while ((line = in.readLine()) != null) {
         out.println("<BLINK>" + line + "</BLINK>");
      }

      out.close();

   }

   public void doPost (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
      doGet(request, response);
   }

}

----- End of source of BlinkFilter.java ----- 

----- Output of hello.bjsp: -----

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
        <title>Untitled</title>
</head>
<body>
Hello world!
</body>
</html>

----- End of output of hello.bjsp -----


----- Output of /blink/Hello: -----

<BLINK><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN"></BLINK>
<BLINK><html></BLINK>
<BLINK><head></BLINK>
<BLINK> <title>Untitled</title></BLINK>
<BLINK></head></BLINK>
<BLINK><body></BLINK>
<BLINK>Hello world!</BLINK>
<BLINK></body></BLINK>
<BLINK></html></BLINK>

----- End of output of /blink/Hello -----


----- Portion of web.xml -----

<servlet>
        <servlet-name>BlinkFilter</servlet-name>
        <servlet-class>BlinkFilter</servlet-class>
</servlet>
<servlet>
        <servlet-name>Hello</servlet-name>
        <servlet-class>Hello</servlet-class>
</servlet>

<servlet-mapping>
        <url-pattern>/blink/Hello</url-pattern>
        <servlet-name>Hello,BlinkFilter</servlet-name>
</servlet-mapping>
<servlet-mapping>
        <url-pattern>*.bjsp</url-pattern>
        <servlet-name>jsp,BlinkFilter</servlet-name>
</servlet-mapping>

----- End of portion of web.xml -----
------------------------------------------------------------------------------
Archives: http://www.egroups.com/group/jrun-interest/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/jrun_talk
or send a message to [EMAIL PROTECTED] with 'unsubscribe' in the 
body.

Reply via email to