When a servlet filter is invoked corresponding to a request for a welcome-file, is there any way for the filter to get the name of the specific welcome-file that is being served up? getRequestURL
stops at the context root (which is presumably because that is the url requested).
I can map a filter to each of the possible welcome-files, but it would be more convenient to have them all go the same filter, and do something slightly different for each of them.
Asked
Active
Viewed 237 times
1

CraftWeaver
- 707
- 1
- 8
- 21
-
Delete all possible default index files but one, and then you'll always know which one is being served. – developerwjk Jan 17 '14 at 19:57
-
That's actually the approach I'm using at the moment to avoid having to identify the specific welcome file served up. However, if there is a way to actually identify the specific welcome file that was served up, I would like to know. – CraftWeaver Jan 20 '14 at 22:52
-
Why would you want to serve different welcome files without controlling it? (i.e. like checking preferred language in a filter and serving a different file per language) – developerwjk Jan 21 '14 at 21:31
-
I have a servlet filter that catches all requests to ensure a user is logged in before serving up anything. If the uri requested doesn't specify a file (i.e., it stops at the context root and a welcome file will be served up), I have to know what that welcome file would be so after redirecting to the login page, I can redirect back to the file that was originally requested -- which is the [unnamed] welcome file. I would rather not stipulate a specific welcome file to use upon the site designers and let them worry about that in web.xml. I need the welcome file name to do the 2nd redirect. – CraftWeaver Jan 21 '14 at 23:43
-
However, this is going to be a non-issue because instead of catching all requests in the filter, I'm only going to catch requests to "protected" pages (none of which will be welcome files), so I won't have to worry about welcome files any more in the filter. – CraftWeaver Jan 21 '14 at 23:50
1 Answers
0
Easy As I think is just take the URL in Session of Welcomefile.jsp and use in Filter.
In your case welcome file is not JSP , in Filter for .xhtml get HttpServletRequest.getRequestURL
() instead of HttpServletRequest.getRequestURI
()

sunleo
- 10,589
- 35
- 116
- 196
-
I'm sorry, but I don't understand the suggestion. The request is `http://localhost/MyApp/`. The welcome-file that got served up was `index.xhtml`. In the servlet filter, `HttpServletRequest.getRequestURI()` returns "/MyApp/". Also, there were no attributes in the session `HttpServletRequest.getSession().getAttributeNames()` [at all] at the point the servlet filter was invoked. – CraftWeaver Jan 20 '14 at 22:58