How can I catch a
com.sun.faces.context.FacesFileNotFoundException
in a Java EE web application?
I tried it with adding the following lines in my web.xml file but I was not successful:
...
<error-page>
<error-code>404</error-code>
<location>/404.jsf</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/404.jsf</location>
</error-page>
<error-page>
<exception-type>FacesFileNotFoundException</exception-type>
<location>/404.jsf</location>
</error-page>
<error-page>
<exception-type>FileNotFoundException</exception-type>
<location>/404.jsf</location>
</error-page>
<error-page>
<exception-type>FailingHttpStatusCodeException</exception-type>
<location>/404.jsf</location>
</error-page>
</web-app>
You need to specify the FQN (Full Qualified Name), not just the N as exception type.
<exception-type>com.sun.faces.context.FacesFileNotFoundException</exception-type>
Alternatively, if you already happen to use OmniFaces, register its FacesExceptionFilter and then the FacesFileNotFoundException will be handled as 404.
Related
It seems an old qs , but i am not getting any proper suggestion.
Steps to produce error :
Scenario One :
1 : Logging in two tabs of same browser with same user credential.
2 : Logging out from one tab .
3 : Logging in again.
I am seeing : This XML file does not appear to have any style information......,
<?xml version="1.0" encoding="UTF-8" ?>
- <partial-response id="j_id1">
- <changes>
- <update id="j_id1:javax.faces.ViewState:0">
- <![CDATA[ 1ZFe3NbsDVn3BWdUDEmAPV96v XXXXXXXX...]]>
</update>
</changes>
</partial-response>
Scenario 2 :
The same error when the restart tomcat and logging in .
Please suggest me How to fix this.
My Web.xml content :
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
I m using Primeface 4 with jsfVersionMojarra-2.1.26 also 2.2.4 Even i am shocked why both versions are in my pom. Anyway this i will check.) . But i am pretty sure this will not cause this issue.
Even though I found some similar queries on the topic but can't find any answer suitable to my problem. My requirement is as follows -
I have installed my app (MyApp) in webapps dir of Apache Tomcat ver 7 web server. The dir structure is
/
|
|----api/
|
|----WEB-INF/
|
|----META-INF/
I have some static html files in the "api" dir(say index.html) which I want to access in the following way through a browser - http://localhost:8080/myapp/api/index.html
However, I can't access any static resources (html files) in this way. As far as I know any static outside WEB-INF can be accessed directly through the browser but I can't do it.
My web.xml looks something like this -
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MyApp</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.core.Application</param-name>
<param-value>com.mycomp.MyApp</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/myapp/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
I'll appreciate any good help on this.
Thanks.
Try replacing the value for the tag url-pattern with some different name like /rest/* instead of myapp.
Now try accessing your url.
I have root.war and cgi-bin-perl directory under Jetty's webapps directory. I am able to run the UI code in root.war, but I am not able to read cgi files and xml files under cgi-bin-perl directory, e.g. hello.cgi, plugin.xml. It returns the error "cannot be found". Here is my etc/webdefault.xml file. What do I miss?
<servlet>
<servlet-name>PerlCGI</servlet-name>
<servlet-class>org.eclipse.jetty.servlets.CGI</servlet-class>
<init-param>
<param-name>commandPrefix</param-name>
<param-value>/usr/bin/perl</param-value>
</init-param>
<init-param>
<param-name>cgibinResourceBase</param-name>
<param-value>/opt/jetty/webapps/cgi-bin-perl</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PerlCGI</servlet-name>
<url-pattern>*.pl</url-pattern>
</servlet-mapping>
Your servlet mapping means that only patterns that end in pl will be executed by the servlet....there is nothing here that will serve out other files under that url.
If you want access to those files then you should setup a default servlet under that url space and let it serve out those files. By default jetty will not let you download whatever files you like, you have to configure it to do that!
i declare a global exception handler in web.xml
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/exceptionHandler</location>
</error-page>
it works fine most of the time. But it cannot capture the exceptions thrown from the prepare method in struts2 actions
anyone know why
Probably because Struts2's ExceptionMappingInterceptor catches exceptions and maps them to error pages itself.
You can use the following in your struts.xml:
<global-results>
<result name="error">/WEB-INF/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
Alternatively, you could remove the ExceptionMappingInterceptor from the interceptor stack if you really want to use the web.xml method.
How can I enable SSI on Tomcat 7?.
I follow the directions however it doesn't work. I changed my main file's extension from html to shtml (not imported one) and unquoted that lines at web.xml:
<servlet>
<servlet-name>ssi</servlet-name>
<servlet-class>
org.apache.catalina.ssi.SSIServlet
</servlet-class>
<init-param>
<param-name>buffered</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>666</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
What do do more, where is the wrong?
You also need to uncomment the SSI servlet mapping in web.xml
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
And create $CATALINA_HOME/conf/Catalina/localhost/<your app name>.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context privileged="true" >
</Context>
http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Introduction_to_SSL
You have to add the SSL configuration to the tomcat config this is detailed above and should help you out any questions after reading this let me know