0
votes

Objective

My goal is to get a servlet filter to process requests to the home page before forwarding them to index.jsp.

Problem

I'm having trouble getting my filter to receive requests from "/". It's URL pattern is

<url-pattern>/</url-pattern>

Instead requests to that pattern end up directed straight to index.jsp.

I read a previous post Servlet Mapping / and /* and wonder if mapping to "/" only works if there is no index.jsp in the application folder?

1
What is so unclear about this question? - Usman Mutawakil

1 Answers

2
votes

Your goal is to redirect the user to a servlet before going to the index.jsp page. I would suggest modifying <welcome-file/> in web.xml.

<welcome-file-list>  
<welcome-file>first</welcome-file>  // remember no leading slash
</welcome-file-list>  

<servlet>  
    <servlet-name>firstServlet</servlet-name>  
    <servlet-class>business.firstServlet</servlet-class>  
</servlet>  

<servlet-mapping>  
    <servlet-name>firstServlet</servlet-name>  
    <url-pattern>/first</url-pattern>  
</servlet-mapping> 

This will make sure that your control goes to first servlet before going to the home page