gbohra
gbohra

Reputation: 1

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

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
1. jsf-api-2.0.3.jar
2. jsf-impl-2.0.3.jar
3. jstl-1.0.2.jar
4. primefaces-3.4.jar

Following are the entrires into web.xml file

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

<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

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

Upvotes: 0

Views: 6275

Answers (1)

BalusC
BalusC

Reputation: 1109432

"My JSP 'index.jsp' starting page"? 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

  1. jsf-api-2.0.3.jar
  2. jsf-impl-2.0.3.jar
  3. jstl-1.0.2.jar
  4. primefaces-3.4.jar

First of all, the JSTL version is wrong. It should be at least JSTL 1.1 or preferably 1.2. The EL (expression language, those ${}/#{}) things would otherwise fail to work. Remove jstl-1.0.2.jar and put jstl-1.2.jar in place.

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. I'd align those JSF API/impl versions as well to be the latest available. 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).


As to your 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. 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. The current Tomcat version, 7.x, exist more than 2 years already and is Servlet 3.0 compatible. You should declare your web.xml to match the highest supported version of the target container.

<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. Just get rid of them to minimize noise.


As to your 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. It are <h:form> and <h:panelGrid>.

<CENTER>  

While not immediately a problem, but this HTML element is deprecated since 1998 in favor of 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. You should assure that your learning resources are up to date.


As to your index.jsp: this is completely useless. Remove it altogether. Just change your web.xml from

<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. Note that you shouldn't and don't need *.jsf URL pattern anymore.


See also:

Upvotes: 5

Related Questions