简体   繁体   English

使用JSF2.0和Prime Faces进行安装项目

[英]Setup Project with JSF2.0 & Prime Faces

I am try to setup JSF project with prime faces library When I run this setup it shows be following error 我尝试使用主要面孔库设置JSF项目,当我运行此设置时,它显示以下错误

org.apache.jasper.JasperException: javax.servlet.ServletException: null source
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:54
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

I did not able to find out reason behind it . 我无法找出背后的原因。
following is by setup 以下是通过设置

Folloing are the library I included into web-inf/lib 以下是我包含在web-inf / lib中的库
1. jsf-api-2.0.3.jar 1. jsf-api-2.0.3.jar
2. jsf-impl-2.0.3.jar 2. jsf-impl-2.0.3.jar
3. jstl-1.0.2.jar 3. jstl-1.0.2.jar
4. primefaces-3.4.jar 4. primefaces-3.4.jar

Following are the entrires into web.xml file 以下是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.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param> 

    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

    <context-param>
        <param-name>primefaces.skin</param-name>
        <param-value>none</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>
    </servlet-mapping>

    <welcome-file-list> 
        <welcome-file>index.jsp</welcome-file>
     </welcome-file-list>

    <listener>
        <listener-class>
            com.nsf.ecap.web.base.ECapStartUpServlet
        </listener-class>
    </listener>

</web-app>


login.xhtml login.xhtml

<h:body>   

 <CENTER>  

     <h:panel header="Login Form">    
     <h:Form>  
         <h:PanelGrid columns="2" cellpadding="2">  
         <h:outputLabel value="UserName" for="#{loginBBean.userInfo.username}"> </h:outputLabel>
         <h:inputText value="#{loginBBean.userInfo.username}" label="UserName">   </h:inputText>  
         <h:outputLabel value="Password" for="#{loginBBean.userInfo.password}"></h:outputLabel>  
         <h:inputSecret value="#{loginBBean.userInfo.password}"></h:inputSecret>  
         <h:commandButton value="Login" type="submit" action="#{loginBBean.doLogin}"></h:commandButton>   

        </h:PanelGrid>  

    <h:messages>
    </h:messages>



    </h:Form>
    </h:panel>
</CENTER>  
</h:body>  
</html> 


index.jsp 的index.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">      
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>

  <body>        
    <jsp:forward page="jsp/login/login.jsf"/>      
  </body>
</html>

"My JSP 'index.jsp' starting page"? “我的JSP'index.jsp'起始页”? Please block/ignore/throwaway that tutorial you're reading now. 请屏蔽/忽略/丢弃您正在阅读的教程。 It's only completely confusing you and teaching you bad practices . 这只会完全使您感到困惑,并会教给您不好的做法


As to your list of libraries: 关于您的库列表:

Folloing are the library I included into web-inf/lib 以下是我包含在web-inf / lib中的库

  1. jsf-api-2.0.3.jar JSF的API-2.0.3.jar
  2. jsf-impl-2.0.3.jar JSF的IMPL-2.0.3.jar
  3. jstl-1.0.2.jar JSTL-1.0.2.jar
  4. primefaces-3.4.jar primefaces-3.4.jar

First of all, the JSTL version is wrong. 首先,JSTL版本是错误的。 It should be at least JSTL 1.1 or preferably 1.2. 它至少应为JSTL 1.1或最好为1.2。 The EL (expression language, those ${} / #{} ) things would otherwise fail to work. EL(表达语言,那些${} / #{} )东西将无法正常工作。 Remove jstl-1.0.2.jar and put jstl-1.2.jar in place. 删除jstl-1.0.2.jar并将jstl-1.2.jar放到位。

Further it looks okay. 进一步看来还可以。 It only surprises me that you've more than 2 years old JSF API/impl versions while you've a fairly recent (less than 2 weeks) PrimeFaces version. 令您惊讶的是,您使用的JSF API / impl版本已有2年以上,而您的PrimeFaces版本却比较新(不到2周)。 I'd align those JSF API/impl versions as well to be the latest available . 我将这些JSF API / impl版本也调整为最新版本 It's currently already at 2.1.13 (note: it's now composed of only one JAR file javax.faces.jar instead of two JAR files). 当前已经是2.1.13 (注意:它现在仅由一个JAR文件javax.faces.jar组成,而不是由两个JAR文件组成)。


As to your web.xml : 至于您的web.xml

<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">

This is declared conform Servlet 2.5 spec which is over 6 years old already. 声明已经符合6年以上的Servlet 2.5规范。 Are you sure that you're running such an outdated container? 您确定您正在运行这样一个过时的容器吗? Given the presence of the JSF and JSTL libraries, I assume that you're using Tomcat. 考虑到JSF和JSTL库的存在,我假设您正在使用Tomcat。 The current Tomcat version, 7.x, exist more than 2 years already and is Servlet 3.0 compatible. 当前的Tomcat版本7.x已经存在2年以上,并且与Servlet 3.0兼容。 You should declare your web.xml to match the highest supported version of the target container. 您应该声明您的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">

Further, those javax.faces.STATE_SAVING_METHOD and javax.faces.DEFAULT_SUFFIX entries represent the default values already. 此外,那些javax.faces.STATE_SAVING_METHODjavax.faces.DEFAULT_SUFFIX条目已经表示缺省值。 Just get rid of them to minimize noise. 只是摆脱它们以最小化噪音。


As to your login.xhtml : 至于您的login.xhtml

<h:Form>  
     <h:PanelGrid columns="2" cellpadding="2">  

Tag names are case sensitive. 标签名称区分大小写。 The <h:Form> and <h:PanelGrid> doesn't exist at all. <h:Form><h:PanelGrid>根本不存在。 It are <h:form> and <h:panelGrid> . <h:form><h:panelGrid>

<CENTER>  

While not immediately a problem, but this HTML element is deprecated since 1998 in favor of CSS. 虽然不是立即有问题,但是自1998年以来, 不推荐使用此HTML元素,而推荐使用 CSS。 Also, seeing it in uppercased flavor instead of <center> , which is very typical for pre-90's HTML style, doesn't give me the impression that you're reading the most recent and right books/tutorials to learn web development. 另外,以大写字母代替<center>来查看它,这对于90年代以前的HTML风格而言是非常典型的,这给我的印象不是您正在阅读最新,最正确的书籍/教程来学习Web开发。 You should assure that your learning resources are up to date. 您应该确保您的学习资源是最新的。


As to your index.jsp : this is completely useless. 至于你的index.jsp :这是完全没有用的。 Remove it altogether. 完全将其删除。 Just change your web.xml from 只需更改您的web.xml

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

<welcome-file-list> 
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

to

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

<welcome-file-list> 
    <welcome-file>login.xhtml</welcome-file>
</welcome-file-list>

and this way login.xhtml will show up as "home page" when you access / in your webbrowser. 这样,当您在网络浏览器中访问/时, login.xhtml将显示为“主页”。 Note that you shouldn't and don't need *.jsf URL pattern anymore. 请注意,您应该也不再需要*.jsf URL模式。


See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM