开发者

JSF not being rendered

开发者 https://www.devze.com 2023-02-07 19:00 出处:网络
I\'ve got a tiny webapp with index.jsp that forwards (it mostly only contains): <jsp:forward page=\"/pages/inputname.jsf\" />

I've got a tiny webapp with index.jsp that forwards (it mostly only contains):

<jsp:forward page="/pages/inputname.jsf" />

web.xml contains (in addition to everything else you'd expect; see more below):

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

inputname.jsp isn't rendering (here's the URI):

http://localhost:8080/simpleWeb/index.jsp

The page appears thus in the browser (label, input edit field, button):

#{msg.prompt} #{personBean.personName} #{msg.button_text}

I'm guessing this is because it's not getting through the Faces servlet. However, I'm uncertain of how to force it through. (Note that I'm elsewhere, with RichFaces and MyFaces, having similar trouble with .xhtml files too, but I'd like to get this simpler case solved first.)

The tutorial has me using these libraries (via Maven), in WEB-INF/lib/:

avalon-framework-4.1.3.jar
commons-beanutils-1.7.0.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-logging-1.1.jar
jsf-api-1.2_02.jar
jsf-impl-1.2-b19.jar
jstl-1.1.2.jar
log4j-1.2.12.jar
logkit-1.0.1.jar
servlet-api-2.3.jar
standard-1.1.2.jar

Any help would be greatly appreciated.

web.xml (yes, it has the DOCTYPE web-app header):

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>开发者_如何学Go;
    </context-param>
    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</param-value>
    </context-param>

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>

    <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>
    </servlet-mapping>
</web-app>


Two solutions:

  1. The index.jsp needs to be called as index.jsf by browser.
  2. The index.jsp should fire a redirect rather than forward. JSTL <c:redirect> may be useful.

Regardless, such an index.jsp is pretty pointless. Just add /pages/inputname.jsf as <welcome-file> in web.xml and provide a blank /pages/inputname.jsf file next to the real /pages/inputname.jsp to fool the server that the file exist (otherwise it will go 404).

As to the web.xml, the DOCTYPE doesn't belong there. It's an ancient remnant of Servlet 2.3 approach and before (almost a decade old already). On Servlet 2.4 and newer, there are XSD's. Even more, since you're using JSF 1.2, the web.xml should be declared as at least Servlet 2.4, preferably higher, the highest your container can support, so that you can utilize the newest available API facilities. Tomcat 5.5 is Servlet 2.4, Tomcat 6.0 is Servlet 2.5 and Tomcat 7.0 is Servlet 3.0.

See also:

  • JSF 1.2 tutorial with Eclipse and Tomcat


I have something similar, this is what is used for redirect:

<body>
    <%
        response.sendRedirect("index.jsf");
    %>
</body>

trying to put "/index.jsp" in the browser brings you to "/index.jsf".

0

精彩评论

暂无评论...
验证码 换一张
取 消