servlet-filters

Adding an HTTP Header to the request in a servlet filter

I'm integrating with an existing servlet that pulls some properties out of the HTTP header. Basically, I'm implementing an interface that doesn't have access to the actual request, it just has access to a map of k->v for the HTTP headers. I need to pass in a request parameter. The plan is to use a servlet filter to go from parameter t...

Struts2 combine with domain specific servlet

I have struts2 web application. Right now I need embed with help of iframe some functionality from stand-alone servlet. But according to following rule, servlet is never get calling. <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> Unfortunately I cannot change it to /prefix/...

How to block a IP address using web.xml ?

How can I block a ip address with some configuration on web.xml? Do I need a filter? How can I implement one? ...

How to specify more than one named Servlet to be wrapped by a filter?

How to specify more than one named Servlet to be wrapped by a filter? ...

Web Form based login in Java

How can I block access to the site if a user is not logged in? Under web.xml > Security I checked Form authentication then I selected Login and Error page, but I don't know how to block the access and redirect the user to the login page. Do I need a filter? If so, how can I get the login url I specified? And how should I call the vali...

Using a Filter to serve a specific page?

Hi, I am using a class which implements Filter for my jsp stuff. It looks like this: public class MyFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.getRequestDispatcher("mypage.jsp").forward(req...

Servlet.init() and Filter.init() call sequence

In which order are Servlet.init() and Filter.init() methods called in java web application? Which one is called first? Are all Servlet.init() methods called before than any Filter.doFilter method? ...

How do I make "simple" throughput servlet-filter?

I'm looking to create a filter that can give me two things: number of request pr minute, and average responsetime pr minute. I already got the individual readings, I'm just not sure how to add them up. My filter captures every request, and it records the time each request takes: public void doFilter(ServletRequest request, ...() { ...

How to build a WebAppDescriptor with a filter class and servlet class?

I'm working on setting up a Jersey test suite for a servlet and a servlet filter that I want to test behavior of the combination of the two for. What I'm confused is how the Jersey documentation states how to build WebAppDescriptor using the WebAppDescriptor.Builder class, specifically between the servletClass() and the filterClass() me...

servlet vs filter

What is the difference between a servlet and filter? What do you recommend to use authorization to pages? ...

in servlet Filter's method doFilter does not call

i have to create a program to login on facebook using example http://code.google.com/p/facebook-java-api/wiki/Examples but when i run project then i get my doFilter method does not call after complete init method ...

Need to use Unit testing famework for testing J2EE Components like Servlets , Filters and JPA.

I need to create unit tests for J2EE components like Servlets, Filters and JPA code which would call it's life cycle methods automatically and would integrate with Maven2 and Continuum and can be run from IDE itself. Can you suggest something? Thanks, Vaibhav ...

Tomcat/Hibernate Problem "SEVERE: Error listenerStart"

I downloaded working example of hibernate (with maven) and installed it on my tomcat, it worked. Then I created a new web project in MyEclipse, added hibernate support and moved all source files (no jar) to this new project and fixed package/paths wherever was necessary. My servlets are responding correctly but when I add "Listener" in w...

When entityManagerFactory is not named "entityManagerFactory" ...

My webapp contains many entityManagerFactories (DBs) , each has its unique name , such as entityManagerFactoryApp , entityManagerFactoryBusiness , entityManagerFactoryForum ...etc. In a webapp , I have to add OpenEntityManagerInViewFilter to achieve "Open Session in View" pattern. <filter> <filter-name>Spring OpenEntityManagerInVie...

How to close a HTTP connection from the HttpServlet

I'm running a servlet in Tomcat 6.0.26. The servlet accepts file upload from the client by HTTP POST. I'd like to stop the file uploading from the HttpServlet side. I tried the following methods with no luck: close the request inputstream send error code HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE and flush response do 1 and 2 in a...

Servlet filters for abuse prevention? (DoS, spam, etc)

I'm looking for a servlet filter library that helps me secure our web service against unauthorized usage and DDoS. We have "authorized clients" for our web service, so ideally the filter would help detect clients that aren't authorized or behave improperly, or detect multiple people using the same account. Also we need a way to prevent ...

Can I exclude some concrete urls from <url-pattern> inside <filter-mapping>?

I want some concrete filter to be applied for all urls except for one concrete (i.e. for /* except for /specialpath). Is there a possibility to do that? sample code: <filter> <filter-name>SomeFilter</filter-name> <filter-class>org.somproject.AFilter</filter-class> </filter> <filter-mapping> <filter-name>SomeFilter</filte...

Servlet filters - passing an attribute not working with RequestDispatcher#forward

Hi, I'm trying to set up a site which allows users to create their own page - as a subdomain of the site, and so what I'm currently trying to do is to have a filter which looks at the subdomain, and if it's not in use, or if it's reserved, then the user will be forwarded to a page where they choose their subdomain name. The problem that...

Web.xml - url pattern mapped twice

A web.xml of ours contains following excerpt.. <servlet> <servlet-name>testServlet</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>testServlet</servlet-name> <url-pattern>*.ht...

Useful Servlet Filters to analyze website usage patterns

I'm looking for some powerful j2ee servlet Filters that make it simpler to track, monitor, block, analyse etc. Java web applications and (Tomcat/Glassfish etc.) web servers. I'm more of a programmer than a heavy-duty server administrator, so the reason I'm looking for a software solution is that I don't want to spread out configuration ...