This question already has answers here:
Set default home page via <welcome-file> in JSF project
(3 answers)
Closed 7 years ago.
Our application JSF2/weblogic10.3.4 has different client folders deployed in root context as below.
app->webapp->ClientA->index.jsf
->ClientB->index.jsf
If the user request our app with client name, we need to display the corresponding index.jsf.
If the browser request is http://server/ClientA, we should display http://server/ClientA/index.jsf
If the browser request is http://server/ClientB, we should display http://server/ClientB/index.jsf
How can we achieve this?
Register it as <welcome-file> in the web.xml.
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
You only need to create empty files with exactly that name next to the existing index.xhtml files in the same folder, so that the container is fooled that those files really exist, otherwise you will still get 404s.
An alternative is to replace the FacesServlet URL pattern of *.jsf by *.xhtml so that you never need to fiddle with virtual URLs.
...
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
Related
I have the folder containing a client-side-html-template ("template.xhtml"). The folder resides in public folder (not in WEB_INF).
When saved the file with suffix "xhtml" and wrap the content with "<ui:composition", then client side (ajax) request can access.
However, when I save it to "template.html" and delete the "<ui:composition", then client ajax cannnot access this page (401).
My web.xml has this mapping:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>xhtml</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<security-constraint>
<display-name>Restrict raw XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
How can I serve common "html-files" by client side ajax request without intercepting these files by jsf/facelets?
Found a simple way without the need to change web.xml:
I changed the static "html" files to "htm".
i would like to remove numerics, symbols and file extensions in the url using netbeans. I tried the following code in web.xml but it aint works
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
Answers are welcome
Download the jar http://urlrewritefilter.googlecode.com/files/urlrewritefilter-4.0.3.jar and XML file http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/urlrewrite.xml
Add urlrewrite.xml into your web-INF folder then add jar file into your libraries .Then isert this segment into your web.xml which defines the filter mapping
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Consider if your href is <a href="login.jsp">. In your urlrewrite.xml you can see the following code
<rule>
<from>/Authentication</from>
<to >/login.jsp</to>
</rule>
The <to> represents your native URL you can paste your native url here .
The <from> represents the altered URL that will be shown on the browser URL .
After editing the urlrewrite.xml you should include only your altered URL in the href tag i.e after changing the urlrewrite.xml your href should should call tha altered URL
<a href="/Authentication">
Thats it now URL wil shown with http:abc.com/Authentication/ instead of http:abc.com/login.jsp/
I am using <welcome-file> in web.xml. My welcome file is at faces/index.xhtml. Everything is working fine except that the full URL for the welcome file is not shown in browser address bar. When I type in
http://localhost:8080/hello1/
I want to see in browser address bar
http://localhost:8080/hello1/faces/index.xhtml
How do I get the URL to appear? Here's my web.xml code fragment
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
I am trying to create a JSF 2.0 application in eclipse with tomcat7. The project is running successfully but the jsf html and core components are not rendered in browser. I think Faces Servlet I have configured in web.xml.
Following is the web.xml file -
<welcome-file-list>
<welcome-file>faces/index.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)</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>
I have my index.xhtml page outside WEB-INF. Its shown in browser but the jsf components are not see in browser. Can anyone please tell what is going wrong.
I have included following jars in WEB-INF/lib -
1. commons-annotations.jar
2. commons-beansutil.jar
3. commons-collection.jar
4. commons-digester.jar
5. commons-logging.jar
6. jsf-api.jar (from mojra 2.0)
7. jsf-impl.jar (from mojra 2.0)
8. jstl.jar
9. standard.jar
Thanks
Try these .. These were specified to me for my own question once..
You don't need and even should not include the JSF jars. Those are already part of Java EE.
Secondly, you definitely don't need and absolutely should not use the separate Facelets jar in combination with JSF 2.x. Facelets is already part of JSF 2.x.
You also should not include the JSTL jar. That one too is provided by Java EE. If u have commons jars by Apache commons, then those are fine but they are NOT needed for JSF. Include them only if you want to use them directly in your application code.
Try to get latest JSF (mojara 2.x).
Also you can modify your web.xml like this and try:
<welcome-file-list>
<welcome-file>index.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>*.xhtml</url-pattern>
</servlet-mapping>
When I tried, I removed adding jsf jars separately. And it worked, displaying all the jsf tags. Also make sure you have all the required taglibs in your xhtml page, namely :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
See if this works.
Please change your servlet mapping shown in your original question to
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
to make it work, i.e. to have your content (which is already happily served by Tomcat) rendered via JSF2.
I had this problem too, and as this question is the first result on google queries about JSF not parsing xhtml files, here is what I have done to solve:
In my case I had a dependency on weld-servlet, version 2.2.1, when I removed it from classpath the JSF started rendering.
Hope this help!
My problem is similar to:
JSF tags not rendered, JSf tags not being rendered and also JSF tags not being rendered as HTML no suggestion there helped me.
Basically the problem is that regardless of going through a welcome page or not the page is not rendered. IE tries to download the file and chrome basically just skips all the jsf tags. It's obvious that it wasn't translated by the framework but I don't understand why.
The back story is that I did a pilot for a conversion of a system from jsf 1.2 into jsf2. The pilot was successful I managed to get it to work in the pilot branch. However when I'm trying to achieve the same thing for real this time I can't get it to work.
The usual problem seems to be (accordingly to veteran answerer BalusC):
The page URL did not match the url-pattern of the FacesServlet, thus it had not any chance to parse the tags.
OR: The xmlns declarations for JSF components are missing in tag, thus it was treated as plaintext.
The usual fixes seems to be:
Include xmlns in html declaration (I have this in both web.xml and the .xhtml files)
Include or modify Faces Servlet Mapping in web.xml. I can however find no fault in mine. I also tried switching out /faces/* to *.xhtml. Parts that I see as relevant in web.xml included below (Whole file is big, this is a big system):
Part of web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_5.xsd"
version="2.5">
<context-param>
<description>
Tell the runtime where we are in the project development
lifecycle.
</description>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<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>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<welcome-file-list id="default">
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
I'm aware that the welcome file is a html file but this worked in the pilot. That file uses
<body bgcolor="#FFFFFF" onload="window.location='portal/login/login.jsf'">
</body>
To get things going. if I manually type the adress in to some random test page containing little and simple code the problem still occurs so the problem feels unrelated to welcome page.
Will gladly assist with any additional information and I'm really stuck here in a bad spot. Thanks for reading.
Resolved by editing faces-config to include xmlns:xsi.