jsp - Struts2 custom 404 error page never shows -


i'm using struts2 framework webapp. while trying create custom 404 error page discovered struts2 doing more work me intended.

i use struts.xml , web.xml file. in web-xml file added following code:

<error-page>     <error-code>404</error-code>     <location>/error/error404.jsp</location> </error-page> 

now, when start webapp goes homepage usual. when try urls of type (all urls don't exist):

http://localhost:8080/mywebapp/fhgfhfhfhgfhgfhfhfh http://localhost:8080/mywebapp/fhgfhfhfhgfhgfhfhfh.action 

struts process request, run interceptors, , automatically redirect default page. have expected 404 error page shown on these pages. removed line in struts.xml still redirects!

<default-action-ref name="index" /> 

when use following url:

http://localhost:8080/mywebapp/fhgfhfhfhgfhgfhfhfh.jsp 

struts shows blank screen , no request being procesed (no interceptors, no redirecting...). find weird because don't see what's invalid request (other .jsp file doesn't exist)

so guess need modify struts.xml can override default redirecting behaviour (i don't want 404 error covered going homepage), , web.xml handle arbitrery obscure requests (so url being typed in user @ handled instead of showing blank screens. missing in configuration?

ps: i'm not talking java exceptions/errors, http errors. hava exceptions handled want them behave.

i found reasons why not showing.

the problem blank screen follows: path 404 page not correct. should path starting webcontent folder, , starting slash "/".

the problem default action server reboot or cache problem. close browser , ide, , restarted everything. default-action-ref gone.

i discovered interesting quirk: struts2 handles action mappings, example:

http://www.mywebsite.com/webapp/whatever http://www.mywebsite.com/webapp/whatever.action 

but not handle server resources (notice file extensions)

http://www.mywebsite.com/webapp/whatever.zip http://www.mywebsite.com/webapp/whatever.jsp http://www.mywebsite.com/webapp/whatever.html 

you can remedy adding additional filter mapping in web.xml file:

<filter-mapping>     <filter-name>struts2</filter-name>     <url-pattern>/*</url-pattern> </filter-mapping>  <filter-mapping>     <filter-name>struts2</filter-name>     <url-pattern>/error/*</url-pattern>     <dispatcher>error</dispatcher> </filter-mapping> 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -