Hey all, This is my first question here!
I'm trying to setup custom error pages in my JBoss RESTful web service. I'm starting with the 400 error, so in my web.xml I've added
<error-page>
<error-code>400</error-code>
<location>/400.html</location>
</error-page>
and I've placed 400.html at the root of my war file (I've also tried placing it at the root of WEB-INF). Unfortunately, I keep getting 404's when I'm supposed to get 400's, presumably because JBoss can't seem to find 400.html. Any ideas what I'm doing wrong?
Might it be because my servlets are mapped to the root?
<servlet-mapping>
<servlet-name>api</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
if so, what are the alternatives?
Thanks!
For posterity: I was able to finally get this working by redirecting errors to a page that Spring MVC had a controller for. The controller just returned a null ModelAndView. Because it was a RESTful service, I really didn't need to have any HTML emitted anyway.
Related
I have the following problem:
In my web.xml I define how to serve pictures like so:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
<url-pattern>*.png</url-pattern>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
On Tomcat this works fine but on IBM Websphere 8.5.5.9 I get the following error:
"SRVE0303E: Servlet name for the servlet mapping *.css could not be found."
On another site I already found a solution for this issue (https://www.ibm.com/developerworks/community/forums/html/topic?id=5f4420ba-0754-43fe-8c87-91acc588d9fc) so I also created the ibm-web-ext.xml exactly the same as in their solution but the error still persists.
Does anyone know what I could do differently?
I found the answer to my problem, thanks to #MigratedPigeon because he got me thinking about the class of my default servlet.
A tomcat server has a default servlet, the class for tomcats default servlet is
org.apache.catalina.servlets.DefaultServlet
Websphere on the other hand does not have a default servlet, thats why I get the error "Servlet Name could not be found".
As in the answer I linked in the original question, static file serving can be activated by websphere by using the web-ext.xml file but that still did not solve the issue of my web.xml file having a "default" servlet.
In our application we use spring, so in the end I replaced the default servlet in web.xml with springs dispatcher servlet and now my web.xml file is valid for both, tomcat and websphere.
you should also mention this in your web.xml
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>your servlet class</servlet-class>
</servlet>
Servlet mapping is done based on the value mentioned in the "" tags and respective servlet will be called.
With wicket is is possible to set 500 in to ways:
In WicketApplication class like that
getApplicationSettings().setInternalErrorPage(MyError500.class);
Via "classical" way in web.xml:
<error-page>
<error-code>404</error-code>
<location>/404</location>
</error-page>
Note that in case of web.xml url /404 is mapped to same Error page.
Could someone provide me a difference? Is it enough to use just web.xml with page url mapping or it is neccessary to use both files?
404 is when your user hits an url for which there is no page/resource/servlet.
Internal error page is 500.
Wicket will prefer its application setting. Depending on another setting (org.apache.wicket.settings.ExceptionSettings#getUnexpectedExceptionDisplay()) Wicket could be configured to use /500 from web.xml.
Any other non-Wicket Servlet/Filter in this application may have its own logic or fallback to /500.
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 a WAR file with a web application that has been deployed to a weblogic stream.
The JSP part works fine, but it can't find the servlets. Possible due to the lack of mapping in my web.xml file.
I was working fine on Tomcat 6, but can't seem to find using weblogic.
I used annotation #WebServlet("/actionOne") but this doens't seem to work.
I am a little confused about how to map these correctly via the web.xml file.
the servlets are .java files and located at WEB-INF/classes/com/foo/bar/
So far I have added the following the web.xml file but the servlet-mapping section has me confused.
<servlet>
<servlet-name>actionOne</servlet-name>
<servlet-class>com.foo.bar.actionOne</servlet-class>
</servlet>
<servlet>
<servlet-name>actionTwo</servlet-name>
<servlet-class>com.foo.bar</servlet-class>
</servlet>
Hopefully the above is correct, the next section I'm not sure how to use and would appreciate some help.
<servlet-mapping>
<servlet-name>actionOne</servlet-name>
<url-pattern>/actionOne</url-pattern>
</servlet-mapping>
The servlets are being called from the jsp via a Form action="actionOne"
My mapping was correct, it seems the issue was related to a different version of servlet.api in the weblogic modules folder. 2.5 instead of 3.0. This resolved the issue.
I used to build my projects with maven. Now I want to do it 'manually'. But I struggle a little bit with directory order and other stuff. I first just created a new dynamic web project in eclipse and added JSF libraries. Now I tried to deploy a hello world page onto a tomcat 7. But jsf-tags are not getting rendered.
Here is my directory structure:
Anybody has an idea where the mistake is? Am I missing a library or is my structure wrong?
cheers
It finally works! thank's to balusc
But jsf-tags are not getting rendered.
This means that the FacesServlet isn't mapped in web.xml or you didn't make the URL in browser address bar to match the url-pattern of the FacesServlet. The FacesServlet is the one responsible for parsing JSF tags and doing all the JSF works.
Assuming that the url-pattern of the FacesServlet as definied in web.xml is *.jsf, then you need to open the start.xhtml by http://localhost:8080/fitnessverwaltung/start.jsf instead of http://localhost:8080/fitnessverwaltung/start.xhtml.
You can also change the url-pattern to *.xhtml, then you don't need to worry about this.
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>