【问题标题】:Suddenly stopped working. .xhtml Not Found in ExternalContext as a Resource突然停止工作。 .xhtml 在 ExternalContext 中找不到作为资源
【发布时间】:2015-01-01 16:59:45
【问题描述】:

在开发我的 web 应用程序时,一切正常,直到创建新的 .xhtml 页面后出现问题。新页面未呈现标签。现在,当我尝试部署我的 web 应用程序时尝试重新启动后,我收到了错误“/odczytyEE2.xhtml Not Found in ExternalContext as a Resource”。

我的 login.xhtml

<h:body>        
    <h:form id="loginForm">          
        <p:growl id="msg" showDetail="true" life="3000" />
        <p:panel header="Login" style="width: 360px; margin-left:35%; margin-right:45%; margin-top:15%">

            <h:panelGrid id="loginPanel" columns="2">

                <h:outputText value="Username" />

                <p:inputText id="username" value="#{login.login}" ></p:inputText>

                <p:spacer></p:spacer>

                <p:message for="username" ></p:message>

                <h:outputText value="Password" />

                <p:password id="password" value="#{login.password}"  feedback="false"></p:password>

                <p:spacer></p:spacer>

                <p:message for="password"></p:message>

                <p:spacer></p:spacer>

                <p:commandButton action="#{login.loginProject}" value="Login" update="loginForm" ajax="true"></p:commandButton>

            </h:panelGrid>

        </p:panel>

    </h:form>

</h:body> 

我的 web.xml

<web-app version="3.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-app_3_0.xsd">
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</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>
 <context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>#{login.theme}</param-value>
</context-param>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>login.xhtml</welcome-file>
</welcome-file-list>

和我的项目结构: ![项目结构]: (http://imgur.com/YT5F4jk)

这个错误的原因是什么?

我根本没有改变任何东西,只是玩了从 *.xhtml 到 *.jsf 等的 servlet-mapping Firefox中的代码是这样的:

<html xmlns="http://www.w3.org/1999/xhtml"  
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>login</title>
</h:head>
<h:body>        
    <h:form id="loginForm">          
        <p:growl id="msg" showDetail="true" life="3000" />
        <p:panel header="Login" style="width: 360px; margin-left:35%; margin-right:45%; margin-top:15%">

            <h:panelGrid id="loginPanel" columns="2">

                <h:outputText value="Username" />

                <p:inputText id="username" value="#{login.login}" ></p:inputText>

                <p:spacer></p:spacer>

                <p:message for="username" ></p:message>

                <h:outputText value="Password" />

                <p:password id="password" value="#{login.password}"  feedback="false"></p:password>

                <p:spacer></p:spacer>

                <p:message for="password"></p:message>

                <p:spacer></p:spacer>

                <p:commandButton action="#{login.loginProject}" value="Login" update="loginForm" ajax="true"></p:commandButton>

            </h:panelGrid>

        </p:panel>

    </h:form>

</h:body> 

在 Chrom 的 html 中:

<td>Username</td><td><input id="loginForm:username" name="loginForm:username" type="text" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" /><script id="loginForm:username_s" type="text/javascript">PrimeFaces.cw("InputText","widget_loginForm_username",{id:"loginForm:username",widgetVar:"widget_loginForm_username"});</script></td></tr>

当我尝试登录时,我会收到以下消息: ![无法找到匹配的导航案例]: (http://imgur.com/PS6IC33)

我的 Login.java:

public class Login implements Serializable {

    private static final long serialVersionUID = 1L;
    private String password;    
    private String message;
    private String login;
    private Object id;
    private Object bg_color;
    private Object theme = "cupertino";

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }
    @ManagedProperty("#{userDAO}")
    private UserDAO session;

    public void setSession(UserDAO session)
    {
        this.session=session;
    }
    public String loginProject() 
    {   
        boolean result = session.login(login, password);
        if (result) {
            // get Http Session and store username
            HttpSession session = Util.getSession();
            session.setAttribute("username", login);
            //UserView.init(id);
            setId(session.getAttribute("id"));
            setBg_color(session.getAttribute("bg_color"));
            setTheme(session.getAttribute("theme"));

            return "home";
        } else {

            FacesContext.getCurrentInstance().addMessage(
                    null,
                    new FacesMessage(FacesMessage.SEVERITY_WARN,
                    "Invalid Login!",
                    "Please Try Again!"));

            // invalidate session, and redirect to other pages

            //message = "Invalid Login. Please Try Again!";
            return "login";
        }
    }

    public String logout() {
      HttpSession session = Util.getSession();
      session.invalidate();
      return "login.xhtml";
   }

    public Object getId() {
        return id;
    }

    public void setId(Object id) {
        this.id = id;
    }

    public Object getBg_color() {
        return bg_color;
    }

    public void setBg_color(Object bg_color) {
        this.bg_color = bg_color;
    }

    public Object getTheme() {
        return theme;
    }

    public void setTheme(Object theme) {
        this.theme = theme;
    }
}

【问题讨论】:

  • 在整个项目中搜索“odczytyEE2”?
  • 是的。每个 .xhtml 都直接位于 WebContent 文件夹下,并且示例“odczytyEE2.xhtml”中的所有文件仍然存在并且在为其添加另一个 .xhtml 文件和 managedBean 之前正在工作。现在,即使在删除这两个文件之后,我也会收到此错误。不管是 login.xhtml 还是 odczytyEE2.xhtml。更奇怪的是,新添加的页面没有渲染primefaces标签,甚至没有任何jsf标签。

标签: jsf-2 primefaces


【解决方案1】:

login.xhtml 的标题是什么? 要呈现 primefaces 需要有一个 &lt;h:head&gt;&lt;/h:head&gt; 元素,即使它是空的:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<!-- THIS IS IMPORTANT: --->
<h:head></h:head>
<h:body>
    [...]
</h:body>
</html>

【讨论】:

  • 有它&lt;h:head&gt; &lt;title&gt;login&lt;/title&gt; &lt;/h:head&gt;
  • 您的 web.xml 中有 ConfigureListener 吗? &lt;listener&gt;&lt;listener-class&gt;com.sun.faces.config.ConfigureListener&lt;/listener-class&gt;&lt;/listener&gt;
  • 但也许这不是必需的:stackoverflow.com/questions/8716352/…
  • 不,我没有。奇怪的是,在添加新的 .xhtml 页面和一些 bean 之前它确实工作得很好。我没有添加或删除任何 lib、jar 等。它只是没有渲染标签,所以我尝试重新启动服务器和我的电脑。之后我得到这个错误。
猜你喜欢
  • 2016-10-22
  • 1970-01-01
  • 2013-11-11
  • 1970-01-01
  • 2012-10-20
  • 2011-10-09
  • 2016-02-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多