servlet-filters

Handling context-path refs when migrating "/" site to Java EE packaging

An existing Java site is designed to run under "/" on tomcat and there are many specific references to fixed absolute paths like "/dir/dir/page". Want to migrate this to Java EE packaging, where the site will need to run under a context-root e.g. "/dir/dir/page" becomes "/my-context-root/dir/dir/page" Now, the context-root can be easil...

Override getContextPath in an HttpServletRequest (for URL rewriting)

I have a web-app that I would like to extend to support multiple languages with new URLs. For example, www.example.com/home.do stays English, but www.example.com/es/home.do is Spanish. My first thought was to create a Filter which rewrites incoming urls like /es/home.do to /home.do (and sets the Locale in the Request); this works fine....

Issue opening Excel documents with Internet Explorer

I have run into an issue in which IE does not open up the Save As/Open dialog box for an Excel document like Firefox does. So I have created a servlet filter that is using '*.xls' as the url pattern. The issue that I now face (since this is the first filter I have created) is how to get the name of the file that the user wants so that ...

How to remove pre-defined characters from user input in a J2EE web application?

we have a J2EE web application usig Spring MVC. We have a new requirement for our web application where we have to remove certain pre-defined characters from the user input. For example, let's say that the application should remove '<' from all the user inputs. I have come up with 2 approaches to meet this requirement : JSP Level : ide...

Java servlet filter not working on login

I've written a filter class to add a P3P header to every page. I added this to my web.xml: <filter> <filter-name>AddP3pHeaderFilter</filter-name> <filter-class>com.mycompany.AddP3pHeaderFilter</filter-class> </filter> <filter-mapping> <filter-name>AddP3pHeaderFilter</filter-name> <url-pattern>/*</url-pattern> </filter-m...

Servlet Filter: Socket need to be referenced in doFilter()

Right now I have a filter that has the sockets opened in the init and for some reason when I open them in doFilter() it doesn't work with the server app right so I have no choice but to put it in the init I need to be able to reference the outSide.println("test"); in doFilter() so I can send that to my server app every time the if state...

Why is my (Spring Security) servlet filter getting called twice?

Any ideas about why doFilterHttp in my SpringSecurityFilter subclass is getting called twice on each request? I don't really know where to start looking. Feeling a little stumped. I'm reverse engineering a vacationing co-worker's code. To the best I can figure it, here's the relevant configuration: in web.xml: <filter> <filter-name>u...

How to get POST URL with parameters from HttpServletReqest in ServletFilter? (For proxy app)

Due to browser restrictions I need to use a proxy to make an openlayers map work. The OpenLayers.ProxyHost javascript object handles the generation of a URL like: http://webhost:8080/app/proxy/?url=http://WFS_server/options/... Some of the requests will be GET's and others will be POST's. I've written a Servlet Filter that will recie...

Servlet Filters and the OSGi HttpService

I'm working on an OSGi-based application that uses org.osgi.service.http.HttpService which does not support the use of Servlet Filters. Before I realised that I wouldn't be able to use Servlet Filters I was planning to apply a couple of existing Filters. These Filters set the appropriate HTTP headers to: prevent caching of responses c...

Is it possible to use wildcards within J2EE - fitlers?

I would like to apply a filter to severl url endings. The next configuraiton seems to work. <filter> <filter-name>LanguageFilter</filter-name> <filter-class>filters.LanguageFilter</filter-class> </filter> <filter-mapping> <filter-name>LanguageFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter...

ThreadLocal + java.sql.Connection + servlet filter = 2009?

I am writing some servlets with plain old mostly-JDBC patterns. I realized that I have several objects that would like to share a single transaction, and I'd like to enforce that one HTTP transaction = one database transaction. I think I can do this via passing a Connection around in a ThreadLocal variable, and then having a servlet fil...

Configuring javax.servlet.Filter and javax.xml.rpc.handler.GenericHandler at server level

Hi, I have one Filter and few Handlers (GenericHandler), which work fine when configured per web application or web-service. I was just wondering if there is a way of configuring these at server level (at a common place) so that every web application or web service deployed in the server can have them implicitily configured so that I do...

How to redirect to Login page when Session is expired in Java web application?

I'm running a web application in JBoss AS 5. I also have a servlet filter which intercepts all the requests to the server. Now, I want to redirect the users to the login page, if the session has expired. I need to do this 'isSessionExpired()' check in the filter and need to redirect the user accordingly. How do I do it? Edit: I'm setti...

Handling 'session expired' in JSF web application, running in JBoss AS 5

This question is related to my other question "How to redirect to Login page when Session is expired in Java web application?". Below is what I'm trying to do: I've a JSF web application running on JBoss AS 5 When the user is inactive for, say 15 minutes, I need to log out the user and redirect him to the login page, if he is trying to...

Is it possible to write a servlet filter to take inspect HTTP response codes?

Is it possible to write a servlet filter to take inspect HTTP response codes? I want to write a filter that will non-destructively inspect outgoing HTTP response codes. But, there does not seem to be a getResponseCode() like method on the Response object. It is also not clear to me how unhandled exceptions from the servlet are supp...

Java Servlet: pass a request back to default processing.

Hi there, I want a Servlet to handle requests to files depending on prefix and extension, e.g. prefix_*.xml Since mapping on beginning AND end of request path is not possible, I have mapped all .xml requests to my Servlet. The question now is: how can I drop out of my servlet for XML files not starting with "prefix", so that the reques...

Enabling browser caching via java

Good day, I am using CacheFilter to filter a certain path to my server (which outputs an image stream to the response stream). And I've configured it in my web.xml as follows: <filter> <filter-name>imagesCache</filter-name> <filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class> <init-param> <p...

J2EE Filters not able to get cookies?

Why aren't cookies able to be referenced from a servlet filter? It just seems beyond me that J2EE wouldn't allow you to sanitize cookie values: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { r...

Filters Help - Getting 2 filters to work with each other.

Hi I have written 2 filters 1 for a normal user and 1 for a admin yet you have to be admin to login. Here is the source for both of my filters: public class newFilter implements Filter { String UUIDInDB; String UUIDInCookie; public void init(FilterConfig filterConfig) throws ServletException { //To change body of implemented metho...

How do you introspect web.xml from a servlet?

Is there a way for a servlet filter to get a list of all servlets and their mappings? ...