I created a dynamic web project in Eclipse and added the JSF jars manually to the lib (instead using maven). I provided faces servlet configuration in web.xml.
I am trying to see the hello.xhtml output of the file placed webinf folder. But it is throwing:
/hello.xhtml Not Found in ExternalContext as a Resource.
My directory structure is as,
LibraryPro
Java resoures
Webcontent
WEB-INF
lib
application.xml
hello.xhtml
the URL I am using is,
web.xml
<?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_3_0.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>JavaServerFaces</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>hello.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Related
I am developing some software but I am facing this issue
HTTP Status 404 - (projectName)/faces/Login.xhtml - the requested resource not available
In my office laptop it is working fine, but in my home laptop I don't know what's the problem behind this.
I tried to clear, rebuild project again and again but the problem is not going.
My other projects are running good.
here is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>EMSLoginAndAttendanceModule</display-name>
<welcome-file-list>
<welcome-file>Login.xhtml</welcome-file>
</welcome-file-list>
<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>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<session-config>
<session-timeout>45</session-timeout>
</session-config>
</web-app>
this is the structure of my Login.xhtml file
WebContent
|_META-INF
|_WEB-INF
|_faces-config.xml
|_web.xml
|_Login.xhtml
The error was because no libraries were included in the Deployment Assembly so after adding that error was resolved.
Steps to resolve the error:
properties of project than Deployment Assembly
click on Add from right pane than select Java Build path Entries
From there I added all my libs and error gone away.
My web project's .war file has the context root myapp/something and it is defined in the application.xml of the EAR file.
In this project I have some Servlets that work fine with this. But now I added a Server Faces Servlet to the web.xml with the pattern /Monitoring/mySite.
The problem now is that if I call the URL http://somehost/myapp/something/Monitoring/mySite I end up in a NullPointer loop because there is no view available (known Websphere issue, fix for that here).
I thought by setting web/page.xhtml as the welcome-file in the web.xml this should be fixed, but it only applies to the context-root of the application, namely /myapp/something.
So what works is if I make the following calls:
http://somehost/myapp/something/Monitoring/mySite/web/page.xhtml
http://somehost/myapp/something
TL;DR
But I would like to see the page.xhtml when I call http://somehost/myapp/something/Monitoring/mySite.
How can I accomplish this?
/TL;DR
The following is the web.xml of the project:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="myProject" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>This is mySite</display-name>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<servlet>
<description></description>
<display-name>Monitoring</display-name>
<servlet-name>Monitoring</servlet-name>
<servlet-class>some.path.to.Monitoring</servlet-class>
</servlet>
<servlet>
<description></description>
<display-name>MonitoringExtended</display-name>
<servlet-name>MonitoringExtended</servlet-name>
<servlet-class>some.path.to.MonitoringExtended</servlet-class>
</servlet>
<servlet>
<description>
</description>
<display-name>FacesServlet</display-name>
<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>Monitoring</servlet-name>
<url-pattern>/Monitoring</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MonitoringExtended</servlet-name>
<url-pattern>/Monitoring/extended</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/Monitoring/mysite/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>web/page.xhtml</welcome-file>
<welcome-file>faces/web/page.xhtml</welcome-file>
</welcome-file-list>
Here the part of my application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
<display-name>myApplication</display-name>
<module>
<ejb>myApplication.jar</ejb>
</module>
<module>
<web>
<web-uri>myProject.war</web-uri>
<context-root>myapp/something</context-root>
</web>
</module>
</application>
Here the ibm-web-ext.xml (legacy, didn't touch it):
<?xml version="1.0" encoding="UTF-8"?>
<webappext:WebAppExtension xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:webappext="webappext.xmi"
xmi:id="WebAppExtension_1229358884593" reloadInterval="3"
reloadingEnabled="true" additionalClassPath="" fileServingEnabled="true"
directoryBrowsingEnabled="false" serveServletsByClassnameEnabled="true">
<webApp href="WEB-INF/web.xml#WebApp_ID" />
</webappext:WebAppExtension>
And finally the ibm-web-bnd.xml(also legacy, didn't touch it):
<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_123456789" virtualHostName="default_host">
<webapp href="WEB-INF/web.xml#WebApp_ID"/>
</webappbnd:WebAppBinding>
I solved this with a workaround.
What I did is a URL pattern to my page.xhtml, but renamed so it would fit my needs, like this:
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/Monitoring/mySite.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
With this I need a new folder Monitoring in my WebContent folder (for other project I guess it's the webapp folder). There I would place my mySite.xhtml.
Now I can call http://somehost/myapp/something/Monitoring/mySite.xhtml.
Not quite the solution I hoped for (I would like to eliminate the .xhtml), but it works.
And with this I also don't run into the Nullpointer loop bug, because there is no URL pattern that would create it.
I'm trying to set view page for particular URL, but it doesn't work, here is a code:
pretty-config.xml:
<pretty-config>
<url-mapping id="loginPage">
<pattern value="/app"></pattern>
<view-id>/loginPage.xhtml</view-id>
</url-mapping>
</pretty-config>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>FiranyCRM</display-name>
<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>
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
If I set url in browser like this: FiranyCRM/loginPage.xhtml then view will load, but when I change loginPage.xhtml into /app then it doesn't work and error appears on browser "Not found", console in eclipse doesn't say anything about it
I do not understand why I am getting 404 error while trying to access my application
my index.xhtml is in (Web Content)
In my log I have no error
I created my project using eclipse : web dynamic project :
my url :
http://localhost:8080/jsf_getting_started/
I tried with eclipse with tomcat (Run On Server).
My web xml
<?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>jsf_getting_started</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<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>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
The problem is that you have set the mapping of the Faces Servlet as /faces/* so in order to access to your page and be parsed by this servlet you must access to it like
http://localhost:8080/jsf_getting_started/faces/index.xhtml
But the problem with the /faces/* configuration is that the Faces Servlet will even process non-JSF resources like images, JS, CSS scripts, etc.
The best solution would be to change the mapping to *.xhtml and remove all the pages in welcome file list to have only index.xhtml. Your web.xml file will look like this (note that I'm just posting the changes made on the parts described in this answer):
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<!-- no need of the other files... -->
</welcome-file-list>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<!-- The relevant URL mapping when using Facelets and JSF -->
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
After changing the web.xml file, rebuild your project, make sure to undeploy it from Tomcat Server and try again.
You need to add index.xhtml in the welcome-file-list.
getting the below exception when accessing http://localhost:8081/ReportGeneratorJSF/
com.sun.faces.context.FacesFileNotFoundException: /login.xhtml Not Found in ExternalContext as a Resource
I am using JSF 2.0
i have created a login.xhtml inside WEB-INF folder which is using templates of header.xhtml and footer.xhtml using basictemplate.xhtml
// login.xhtml
<ui:composition template="/WEB-INF/template/basictemplate.xhtml">
...
textboxs and submit button
...
</ui:composition>
// web.xml
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ReportGeneratorJSF</display-name>
<welcome-file-list>
<welcome-file>faces/login.xhtml</welcome-file>
</welcome-file-list>
<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>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Can you please provide solution for it.
You have a problem in your files, you need to place them like this :
WEB-INF
- faces-config.xml
- web.xml
login.xhtml
header.xhtml
footer.xhtml
...