Getting a strange error.
I have a few different files in WebContent.
WebContent/page1.xhtml
WebContent/page2.xhtml
WebContent/page3.xhtml
I have my web.xml set up like this:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
...
<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>/01/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/02/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/03/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/04/*</url-pattern>
</servlet-mapping>
When running the web server (JBoss EAP 6.1), I can get to /myapp/01/page1.xhtml, /myapp/01/page2.xhtml, etc. This seems to be the case for everything except for /myapp/03/.
For /myapp/03/, I can get to page2.xhtml just fine, but when I try to get to page1.xhtml I am getting a java.io.FileNotFoundException. I can get to page1.xhtml just fine from all of the other combinations (/myapp/01/, /myapp/02/, /myapp/04/, etc. all the way to 10).
All of the /myapp/##/ stuff goes through the same filter, and the java.io.FileNotFoundException is happening when the chain.doFilter() method is called, but it works fine for all of the other sections, so I don't know if it could be in there or not.
Any ideas would be greatly appreciated.
The root cause of this issue was a path error. The site was set up to use multiple include files, some of the paths for which were set via code. I needed to review every path to ensure that the correct files were being found.
Related
I would like to be able to receive a request on a servlet I made, then analyse the URL and configure the application database based on that, and after the DB is configure forward the request to the regular Faces Servlet.
How should I configure my web.xml? And how can I forward the request to the Faces Servlet?
Here is what I was thinking:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>aws</servlet-name>
<servlet-class>servlets.aws</servlet-class>
</servlet>
<!-- <servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>-->
<servlet-mapping>
<servlet-name>aws</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
System.out.println("configure DB based on URL");
RequestDispatcher rd = request.getRequestDispatcher("FacesServlet");
rd.forward(request, response);
}
However that gives the following error:
I'm trying to implement a custom PDF file servlet (/fileprovider/name?param1=value¶m2=otherValue) on a JSF 2 web application, but when declaring it on web.xml the application always adds .xhtml extension to every request. I believe due to the DEFAULT_SUFFIX context-param.
<!-- ... -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
<param-value>/*.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>MyPDFServlet</servlet-name>
<servlet-class>com.company.servlet.MyPDFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyPDFServlet</servlet-name>
<url-pattern>/fileprovider/name</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- ... -->
The exception thrown is:
FacesFileNotFoundException: /name.xhtml Not Found in ExternalContext as a Resource
So I believe that the path is not mapped correctly, maybe I'm missing something.
Is there any way to specify that I want specific paths to point to custom servlets without adding .xhtml extension?
I am developing a jsf2 + spring3 application with the following filesystem:
webapp
-resources (folder)
-WEB-INF (folder)
--applicationContext.xml
--faces-config.xml
--web.xml
-buy.xhtml
-company.xhtml
-home.xhtml
-sell.xhtml
And I got this in my web.xml:
<welcome-file-list>
<welcome-file>home.jsf</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
My faces-config.xml got nothing about navigation.
When I go to the following URL "http://:8080/website/" I got the "home.jsf" view.
I need to go to the same "home.jsf" view "http://:8080/website/home.jsf" when I write the following URL "http://:8080/website/caminha/"
How can I achieve this? What I need to change in web.xml or in faces-config.xml? Thanks!
This is my web.xml :
<servlet-mapping>
<servlet-name>Faces Servlet</servlet>
<url-pattern>/*</url-pattern>
</servlet-mapping>
When I navigate to:
http://localhost:8080/LearningRoot/index.xhtml
I can see the page just fine, however when I navigate to:
http://localhost:8080/LearningRoot/
I get the error:
An Error Occurred:
The FacesServlet cannot have a url-pattern of /*. Please define a different url-pattern.
But why?
And this is my welcome file:
<welcome-file-list>
<welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>
Because that would mean Everything that ever hits that context-root will be handled by FacesServlet, a requirement that FacesServlet already knows it couldn't possibly fulfill (It obviously doesn't make sense).
To achieve the mapping you intend, use a .xhtml mapping on FaceServlet
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
For my app I'm using Tomcat 6.0.x and Mojarra 1.2_04 JSF implementation.
It works fine, just I would like to switch now to MyFaces 1.2_10 impl of JSF.
During the deployment of my app a get the following error:
ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myApp]] StandardWrapper.Throwable
java.lang.IllegalStateException: No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:106)
at javax.faces.webapp.FacesServlet.init(FacesServlet.java:137)
at org.apache.myfaces.webapp.MyFacesServlet.init(MyFacesServlet.java:113)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
...
Here is part of my web.xml configuration:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<!-- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> -->
<servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
...
<listener>
<listener- class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
Has anyone experienced similar error, and what should I do i order to fix it? Thanx!
EDIT:
I was able to fix the problem. Since I am using delegator for FacesServlet, it turned out that this delegator was causing the problem.
All I needed to do is to make this class implement DelegatedFacesServlet, and I've removed org.apache.myfaces.webapp.StartupServletContextListener. Here is my web.xml now:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<!-- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> -->
<servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Faces Servlet Delegator</servlet-name>
<servlet-class>com.myapp.web.FacesServletDelegator</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet Delegator</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
and here is FacesServletDelegator
public class PLMFacesServlet extends HttpServlet implements DelegatedFacesServlet {
private MyFacesServlet delegate;
public final void init(ServletConfig servletConfig) throws ServletException {
delegate = new MyFacesServlet();
delegate.init(servletConfig);
}
public final void destroy() {
delegate.destroy();
}
public final ServletConfig getServletConfig() {
return delegate.getServletConfig();
}
public final String getServletInfo() {
return delegate.getServletInfo();
}
public final void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
delegate.service(request, response);
} catch(Exception e) {}
}
// some other code...
}
EDIT 2:
Following BalusC advice, I've edited my web.xml a bit, here is the final version:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Faces Servlet Delegator</servlet-name>
<servlet-class>com.myapp.web.FacesServletDelegator</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet Delegator</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
In my case, the removal of the following line from my web.xml:
<load-on-startup>1</load-on-startup>
...was what made the error disappear.
(Was fixing up a pure Tomcat 7 to work with JSF.)