servlet-filters

How can I get the HTTP status code out of a ServletResponse in a ServletFilter?

I'm trying to report on every HTTP status code returned from my webapp. However the status code does not appear to be accessible via the ServletResponse, or even if I cast it to a HttpServletResponse. Is there a way to get access to this value within a ServletFilter? ...

Is doFilter() executed before or after the Servlet's work is done?

The javax.servlet.Filter object can be used both for authentication (where the Filter needs to catch the request before any servlet work needs to be done) and for XSLT translation (where the servlet needs to be completely finished generating content). When does it actually get executed? I know this is implementation dependent (on the we...

Spring MVC and parsing HTML

I have a controller class as in the following code segment: @Controller public class SiteEntryController { @RequestMapping(value="/index.htm") public ModelAndView handleIndex( @RequestParam(value="enableStats", required=false) String enableStats) { ModelMap map = new ModelMap(); ........... return ne...

Init method invocation in filter

Could anyone please tell me why the following line about filter init method invocation is incorrect: The init method on a filter is called the first time a servlet mapped to that filter is invoked. ...

urlrewritefilter problem with velocity template rendering

So after installing UrlRewriteFilter, I set up a rule and a corresponding velocity template. And when I go to the test page, the velocity script is shown as raw code instead of being compiled. example of the code for the rule: <rule> <from>/test/([0-9]+)</from> <to>/downloads/test.vm?Id=$1</to> </rule> example of the urlrewrite...

Modify request parameter with servlet filter

An existing web application is running on Tomcat 4.1. There is an XSS issue with a page, but I can't modify the source. I've decided to write a servlet filter to sanitize the parameter before it is seen by the page. I would like to write a Filter class like this: import java.io.*; import javax.servlet.*; public final class XssFilter...

Is Tomcat's performance reduced by introducing more filters?

Is the performance of tomcat is reduced if we implement more filters in the web application? ...

What's PHP Equivalent of Java Servlet Filter?

On Java side, we have a servlet filter that handles authentication. We don't have to change all other servlet or JSPs to add authentication to the page, unless the page needs customized content. How can we achieve the same on PHP? We don't use any frameworks on PHP. ...

Modify Http response

Hi, I have a need to write a Servlet filter to inspect the HTML being sent out and modify all the links that point to /images in it to a different domain altogether so that they are served from a CDN(content delivery network) rather than my site. Is this recommended and how can I achieve this? -thanks ...

How do I redirect to the current page in Servlet Filter?

I have a page say: /myapp/test.jsp?queryString=Y. The filter needs to redirect to current page. It should go to /myapp/test.jsp (without the query string). The below seems to bring it to to the context root: /myapp. I am running in WAS6.1. public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOExce...

Jetty Filter Problem (ClassNotFoundException)

Hi! I have a groovy project running under jetty for development and under tomcat for production. I wrote a filter called URLFilter I've added the following lines in web.xml (actually I've added to myProj/src/templates/war/web.xml) <filter> <filter-name>URLAbarajeitor</filter-name> <filter-class>filters.URLFilter</filter-class>...

web.xml - Java Servlet Filters - Not being run before processing the JSP page (on Tomcat)

I am fairly new to Servlet Filters and have basically joined a project using them and added an additional filter to the web.xml file (deployed on Tomcat 5.5). I am 95% sure that at some point it was working correctly but now when debugging if I put breakpoints at the top of the JSP page I am trying to view (login.jsp), it's template pa...

Overriding the JSP servlet (filter "*.jsp") to wrap in an authentication model

Hi there, Can the JSP servlet that filters on *.jsp (org.apache.jasper.servlet.JspServlet in Tomcat 6) be extended in some way so whenever someone goes to a JSP page I can do some server side authentication to check whether the user can view the page. Our current technique is a taglib in a common include that is imported into each JSP ...

Exclude filter from certain url's

I'm using a filter in web.xml to check if a user is logged in or not: <filter> <filter-name>LoginFilter</filter-name> <filter-class>com.mycompany.LoginFilter</filter-class> </filter> <filter-mapping> <filter-name>LoginFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> And this works like a charm until...

web.xml - Java Servlet Filters and WebSphere - URL Pattern issues

Hi, So we are running a web application that has been tested on Tomcat, Glassfish, WebLogic and WebSphere. All run correctly except WebSphere. The issue is that filters are not processed for files under a certain directory. For example I have a filter that checks the user's lanuage from browser cookies and another that get the user's u...

How to control cache in JSP page?

I created a Servlet filter with the following code in doFilter: HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.setHeader("Cache-Control","no-cache"); httpResponse.setHeader("Pragma","no-cache"); httpResponse.setDateHeader("Expires", 0); chain.doFilter(request, response); I want to make sure that noth...

Servlet Filter vs. ServletRequestListener

I want to bind a JPA EntityManager to the current thread on each request (via ThreadLocal), what could be done via a ServletRequestListener or Filter. The listener looks cleaner and I don't need the additional possibilities of a filter in this case. But maybe the filter has an advantage I've missed. Should I use a Servlet Filter or a Se...

redirecting a request to a form from a servlet filter

I am in a class that implements javax.servlet.filter. From this class I want to call ((HttpServletResponse)servletResponse).sendRedirect(url) and redirect to a different url (to a jsp with an html form) - the thing is - the url has a very long parameter (could be 5000 bytes long) I understood that there is a limitation on the size of ...

Who will take the roll of service method in filters in java?

Hi Filters are like servlets but managed by the web container but there is service() method in servlets but there is no method called service in filters. There are three only three methods init(), doFilter(), and destroy().Can anybody elaborate on this ? ...

Filters are like servlets. There exists many servlet container.Do filters take the role in servlet container only?

I read everytime Filters are like servlets. Resin is a servlet container. Is there exist any filter container to initialize filters or does it take the role in servlet container only. Can anybody elaborate how it works? ...