0

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?

Community
  • 1
  • 1
Usman Mutawakil
  • 4,993
  • 9
  • 43
  • 80

1 Answers1

2

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

Shurmajee
  • 1,027
  • 3
  • 12
  • 35