tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Purcell" <spurc...@vertisinc.com>
Subject filter question
Date Wed, 23 Feb 2005 19:49:01 GMT
Hello,
I am having trouble with a filter. Code below.
 
What I am trying to achieve is as follows: We have a current web-site, with a lot of jsp pages,
etc. We are moving the code to a load-balanced environment, and I would like to put a hidden
"IP" address into each display page. This way I can know which environment the page came from
when debugging, etc.
 
I figured I could use a 'filter' and have each page insert the IP into itself in a hidden
field. I am unable to achieve my goal and could use a hand if anyone has experience with this.
Is this possible, or will I have to write into a header and then edit each jsp page to show
the value?
 
 
 
Here is what I have, but it does not print anything on pages.
 
web.xml
<filter>
   <filter-name>HelloWorld</filter-name>
   <filter-class>chapter18.HelloWorldFilter</filter-class>
  </filter>
 
  <filter-mapping>
   <filter-name>HelloWorld</filter-name>
   <url-pattern>/*.jsp</url-pattern>
  </filter-mapping>
 
And I have the servlet code from SCWCD book
package chapter18;
 
import java.io.*;
import javax.servlet.*;
 

public class HelloWorldFilter
    implements Filter
{
 
    public void destroy()
    {
    }
 
    public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse, FilterChain
filterchain)
        throws ServletException, IOException
    {
        PrintWriter printwriter = servletresponse.getWriter();
        printwriter.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    }
 
    public void init(FilterConfig filterconfig)
    {
        filterConfig = filterconfig;
        System.out.println("Chapter 18: HelloWorldFilter initialized");
    }
 
    public HelloWorldFilter()
    {
    }
 
    private FilterConfig filterConfig;
}
 
 
Thanks,
Scott

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message