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!
Related
We have a Java Web application running in IBM Websphere Liberty profile server. We have recently developed a Java Servlet which is responsible to generate JFreeCharts using Java library.
Code in web.xml
<servlet>
<servlet-name>GraphicServlet</servlet-name>
<servlet-class>com.test.GraphicServlet</servlet-class>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>GraphicServlet</servlet-name>
<url-pattern>*.img</url-pattern>
</servlet-mapping>
Code in index.html file
<img src="summary/chart.img" height="100" width="100" />
Code in GraphicsServlet.java
This Servlet has doGet method implemented and the business logic in the method generates a chart image file(.png) using JFreeCharts and this image is returned as response in form of stream.
Application flow:
When application is accessed, index.html file is displayed by default and this page has a section where chart generated by JFreeChart needs to be displayed.
Scenario Description:
The Image file is not getting displayed when application is accessed. Using the browser's developer tools, I have found that 404 error is printed when a request is sent to *.img Url. Next, I tried to find out if that Servlet is really deployed on to the server or missed in the .war file by any chance, and I checked the deployment folder in websphere and found the Servlet deployed. Next, I tried to check if Servlet is up and running. From a new browser, I sent a test request like http://localhost:9080/myapp/summary/chart.img, it returned 404 error on to the screen.
I wanted to know why servlet is not getting up. So, I implemented the init() method of HttpServlet in my GraphicsServlet and written a print statement. I didnot get that print when the application finished loading. Finally, I tried with commenting out every line of doGet method, even then I received
404 Error on the screen.
Problem Description: I want to know why the GraphicsServlet is not getting up. Please let me know if there are any techniques to know the reason behind the failure of GraphicServlet.
Update 1:
I tried removing the configuration in web.xml and annotated the GraphicServlet with #WebServlet annotation. Now, I am able to see those print statements and it is now confirmed that GraphicServlet is up and running when annotation is used. So, I started looking at web.xml DOCTYPE tag. The version of Web app DTD was very old. It was 2.3 version, and the Java version we installed is 1.8. Can anyone here let me know whats the problem with WebApp-2.3 ?
Update 2:
I removed the #WebServlet annotation from GraphicServlet and again I tried with xml configuration and also changing the Web-app version from 2.3 to 3.1 (also 3.0) in web.xml file. The GraphicServlet is still not up and running.
Update 3:
I have noticed that javaee-7.0 feature is being used in the Websphere server.xml file.
Thanks for your patience.
Maybe you should change your servlet mapping in web.xml to be like this:
/summary/*.img
Is there way to mount a 404 error page in Wicket-1.5.x without adding:
<error-page>
<error-code>404</error-code>
<location>/NotFound</location>
</error-page>
to my web.xml file?
I have several applications that all use the same/similar Look/Feel. I've extracted out a lot of the common functionality including my error pages to some shared jar files. I'm already mounting a lot of common pages (Login Pages, Error Pages, etc) via an Iinitializer. Is there a way I can do the same for 404 errors?
UPDATE:
In Doing more research I also found this question:
Can I redirect to a valid Wicket page when attempting to access a non-existent page?
Which also seems to state that editing web.xml is the solution.
As I said I have several applications while editing the file isn't hard and there isn't that many, it's one more thing I'll have to remember next time I upgrade them.
If it makes a difference I'm using Tomcat-6.x Is there possibly a way to fake the <error-page> configuration setting in my web.xml by modifying ServletContext?
As far as I know you need those lines in your web.xml, but once you've done that you can still mount your common page along with everything else in your IInitializer:
application.mount(
new QueryStringUrlCodingStrategy("NotFound", NotFoundErrorPage.class));
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
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 .
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, ...).