【问题标题】:JSF2.0 + Richfaces 3.3.3, jsp not found errorJSF2.0 + Richfaces 3.3.3,jsp not found错误
【发布时间】:2012-02-10 09:22:59
【问题描述】:

我在 Netbeans6.9.1 中使用 JSF2.0 + Richfaces3.3.3 + tomcat6.0.29 创建了一个简单的项目

Step1 : File -> NewProject + Select JSF 2.0 + Prefered Page Language as JSP

第 2 步:罐子

JSF2.0 jsf-api.jar
JSF2.0 jsf-impl.jar
JSTL1.1 - Standard.jar
JSTL1.1 - jstl.jar
jsf-facelets.jar (Facelets 1. 1. 15)
richfaces-api-3.3.3.Final.jar
richfaces-ui-3.3.3.Final.jar
richfaces-impl-jsf2-3.3. 3.Final.jar
commons-beanutils-1.8.3.jar
commons-collections-3.2. 1.jar
commons-digester-2.0.jar
commons-logging-1.1.1.jar and hth-api-0.4.0.jar

web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</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>
    <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
    <param-value>true</param-value>
</context-param>

 <context-param>
    <param-name>org.richfaces.SKIN</param-name>
    <param-value>blueSky</param-value>
</context-param>


<!--Configuration for Richfaces-->
<filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<!--End of the configuration part for Richfaces-->

<!--Configuration for Facelets-->
<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.jsp</param-value>
</context-param>
<context-param>
    <param-name>facelets.RECREATE_VALUE_EXPRESSION_ON_BUILD_BEFORE_RESTORE</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>facelets.VIEW_MAPPINGS</param-name>
    <param-value>*.xhtml</param-value>
</context-param>
<context-param>
    <param-name>facelets.SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
</context-param>
<!--End of the configuration part for Facelets-->


<welcome-file-list>
    <welcome-file>faces/welcomeJSF.jsp</welcome-file>
</welcome-file-list>
</web-app>

和 faces-config.xml 文件

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.0"
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-facesconfig_2_0.xsd">

 <managed-bean>
    <description>Managed Bean for HomeContent</description>
    <managed-bean-name>Sample1</managed-bean-name>
    <managed-bean-class>com.test.Sample1</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

</faces-config>

欢迎JSF.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<f:view>
 <html>
<head>   
    <title>JSP Page</title>
</head>
    <body>
      <h:form id="sampleForm" binding="#{Sample1.initForm}">               

        <a4j:outputPanel id="sampleOutputPanel">

          <h:outputText value="UserName : "/>
          <h:inputText value="#{Sample1.username}"/>

          <a4j:commandButton value="Test" 
                             reRender="sampleOutputPanel,output"
                             action="#{Sample1.displayButtonAction}"/>

         <h:outputText id="output" 
         value="Typed username : #{Sample1.displayValue}"/>
    </a4j:outputPanel>
</rich:panel>
</h:form></body> </html></f:view>

和 Sample1.java

package com.test;
import javax.faces.component.html.HtmlForm;

public class Sample1 {

    private HtmlForm initForm;
    private String username;
    private String displayValue;

    public String displayButtonAction() {
        displayValue = username;
        return "";
    }


    public HtmlForm getInitForm() {
        username = "";
        return initForm;
    }


    public void setInitForm(HtmlForm initForm) {
        this.initForm = initForm;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getDisplayValue() {
        return displayValue;
    }

    public void setDisplayValue(String displayValue) {
        this.displayValue = displayValue;
    }
}

我的问题是:

将我的战争部署到我的 tomcat6.0.29 后,运行我的应用程序。 当我单击 a4j:commandbutton 时出现以下错误

HTTP Status 404 - /.jsp not found
type Status report
message /.jsp not found
description The requested resource (/.jsp not found) is not available.
Apache Tomcat/6.0.29

帮帮我。 提前致谢

【问题讨论】:

    标签: tomcat jsf-2 richfaces netbeans-6.9


    【解决方案1】:

    在 displayButtonAction 方法中返回 null

    public String displayButtonAction() {
        displayValue = username;         
        return null;     
    }
    

    或者用返回类型 void 重写你的操作方法

    public void displayButtonAction() {
            displayValue = username;         
    
        }
    

    【讨论】:

    • 您好 Naveen,感谢您的回复。它对我有用。但是在现有的 JSF1.2 应用程序中,我没有为任何 a4j 操作返回“null”值。是否有任何理由在 JSF2.0 中为 a4j 操作返回“null”
    • 隐式导航是从JSF2.0引入的,它将“结果”作为页面名称,例如,导航到“page1.xhtml”,则必须将“结果”作为“page1” .然而,JSF1.2 没有隐式导航,而是通过在 faces-config.xml 中查找匹配(结果)来进行导航。看起来 return "" 在 JSF 1.2 中被处理为 null 而不是在 JSF2.0 中
    • 好的..谢谢 Naveen。我是JSF2.0+richfaces3.3.3的新人。在我上面的配置是否正确???否则任何其他配置丢失???
    【解决方案2】:

    您的操作的返回值用于查找要显示的新视图。通过在 faces-config 中找到匹配项,或者如果那里没有映射,则直接将其用作页面名称。当您返回一个空字符串时,您最终只会以 .jsp 作为文件名。如果要返回同一页面,则返回 null 而不是空字符串。

    【讨论】:

    • 您好,Eelke,感谢您的回复。它对我有用。我没有为 JSF1.2 中的 a4j 操作返回“空”值。为什么 JSF2.0 需要为 a4j:action 返回空值。跟我来。
    • 2.0中增加了结果可以直接命名视图。所以对结果的处理略有改变。
    • 谢谢埃尔克。谢谢你的解释。还有一个疑问,我是(JSF 2.0 + Richfaces3.3.3)的新手。在我上面的配置(web.xml,faces-config.xml)是正确的???或其他任何我想念的东西???
    猜你喜欢
    • 2013-07-12
    • 2011-09-23
    • 2018-12-24
    • 2013-02-20
    • 2012-06-04
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多