Having an @WebServlet(urlPatterns = "/myServlet/"). If the user goes to myapp/myServlet/other, I still want my servlet to catch. So to say, wildcard anything on after the servlet path. How could I do this?
            Asked
            
        
        
            Active
            
        
            Viewed 9,886 times
        
    10
            
            
         
    
    
        BalusC
        
- 1,082,665
- 372
- 3,610
- 3,555
 
    
    
        membersound
        
- 81,582
- 193
- 585
- 1,120
2 Answers
33
            You can use * as prefix or suffix wildcard. In your case, you can use /myServlet/* for a folder mapping.
@WebServlet("/myServlet/*")
The path info (the part after the mapping in the URL) is in the servlet by the way available as:
String pathInfo = request.getPathInfo();
This would in case of myapp/myServlet/other return /other.
See also:
- 
                    2Wow thats incredibly nice! I just tried the * wildcard with urlPatterns, which did not work. But this does as expected. – membersound Oct 19 '12 at 11:11
- 
                    3By the way you just answered my next question (how to get the path) :) – membersound Oct 19 '12 at 11:12
 
    