We have a filter that redirects user to error.html, if the user is not authorized. Right now, we are keeping error.html page inside the WAR, but is there any way to make the html file public so that every war file can access this error page? It would be still better, if we make this html page as a jar and keep it in server/default/lib.
Here is the sample that is used in filter.
`reqDespacher = request.getRequestDispatcher("error.html")`
and the accessing url is
http://localhost/Context_root/error.html
Any help would be appreciated.
In JBoss5 or JBoss6, you can copy and then define this custom error.html inside the /deployer/jbossweb.deployer/web.xml of the server instance that you are running. This will require a reboot of the JBoss instance. Example for error code 404:
<error-page>
<error-code>404</error-code>
<location><relative_path_to_error_html_file_under_jbossweb.deployer_folder></location>
</error-page>
Secondly, instead of re-directing request by specifying a page manually like you are doing currently, you should use the <error-page> and <error-code> deployment directive to define custom error pages. See specify-the-default-error-page-in-web-xml-in-servlet for a detailed example on how to add error-code directives on web.xml.
For JBoss AS7 global error page configuration take a look at how-to-customize-jboss-as7-404-page .
Related
I have web-apps deployed on my server, lets call them ABC and XYZ. I want to show a custom error page page when I try to access an unknown web-app. For example if I try to access localhost/asdfasd it should display my custome error page.
I have tried adding something like below in conf/web.xml, but it doesn't work I still see the default Tomcat 404 error page.
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
But the error-page works when I use it in web.xml of each web-app. So when I try access localhost/ABC/non_existing_page I see my custom error page.
I have multiple webapps deployed on tomcat. I have configured error page in $CATALINA_BASE/conf/web.xml :
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.jsp</location>
</error-page>
My requirement is to create only one error.jsp page that can be accessed by all the webapps. But when I create an error.jsp page and put it in $CATALINA_BASE/error.jsp location, my webapps are not able to access it when an exception occurs say ArithmeticException. It redirects to a blank page instead.
The only way I could access the error page is by creating an individual error page for each application and put it in respective WEB_INF folder. But I want only one error.jsp file that can be shared by multiple webapps. Is it possible?
I have configured my tomcat6 web.xml to show my custom error page by adding these lines, described here
<error-page>
<error-code>500</error-code>
<location>/web_server_error.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/web_server_error.html</location>
</error-page>
Also I came to know for each application deployed I need to put the same configuration as I did for ROOT, which is fine.
My issue is I have a simple folder webapps/docs. If I try to access any file existing in this folder say /docs/mypage.html, I can access it perfectly but if the file or directory doesn't exist in the folder like docs/faq/ I need the same error page but tomcat is showing its 404 error page.
Actually I need it because my client mention this in a vulnerability list, i.e. in this scenario the attacker can get aware of the file structure so we need to show one page on all errors.
I need to know as it is a simple folder instead of any application how to handle this issue or is it simple impossible?
Any help is highly appreciated.
This is not possible in Tomcat 6. Servlet 3.0 specifies global error pages but Tomcat 6 implements Servlet 2.5.
But it's possible to "workaround" by writing a ErrorReportValve class and register it. But beware: This is Tomcat specific!
The folder is not a web application.so your configure does not work!
I have multiple web applications defined in my tomcat. In case of any exception, I want to throw one jsp (done using SimpleMappingExceptionResolver tag of spring). When I put the jsps in the web-inf folder of the web applications, it works fine which is obvious.
But I want to put this jsp at a common place in tomcat such as ROOT library. But if I do this, tomcat is not able to find my jsp. Can somebody tell me if any changes in web.xml is required to make this happen or I should put this jsp somewhere else.
Thanks in advance.
What do you mean by 'picked up' or 'access'? You can put a jsp file on the tomcat ROOT application, and do a 302 redirect into it everytime you encounter exception.
For example place you all-apps generic exception page on webapps/ROOT/generic_exception.jsp, then on each of your apps, add this to the web.xml
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/myapp_error.jsp</location>
</error-page>
That should redirect request into myapp_error.jsp (inside myapp) if any uncaught exception surfaces. Then inside myapp_error.jsp, just perform html meta redirect to /generic_exception.jsp
However the drawback of this approach is you are redirected into different web-app, it's difficult / require extra work if you want to pass session attributes
I'm deploying a web application and I want to have a default 404 page applicable to all my web applications unless stated otherwise in each application web.xml
I've accomplished something changing "jboss-as\server\myapp\deployers\jbossweb.deployer\web.xml" and adding the following
<error-page>
<error-code>404</error-code>
<location>/error404.html</location>
</error-page>
Then all 404 errors I get are redirected to /error404.html without changing each application's web.xml as I wanted.
Anyway the bizarre thing is that each war I'm deploying must have a error404.html copy because it's looking for it in its own context. I tried putting error pages in jboss-as\server\myapp\deploy\ROOT.war and they work for non-defined URLs but not for already defined applications.
Can I have only one copy of my error pages for ALL contexts and that page defined only in one web.xml?
Thanks a lot in advance.
Rafa,
is "myapp" a custom profile you created? If not then try changing the file /jboss/server/all/deployers/jbossweb.deployer/web.xml.
Where "all" is one of the available jboss profiles (all, default, standard, ...).