0
votes

When i add JSF related tags to web.xml nothing is working and it gives an error. If I remove XML tags in web.xml then all .jsp and servlets are working fine. I also added jsf-api.jar,jsf-impl.jar,jstl.jar and standard.jar to lib folder of my project still it is not working so i added these jar files to lib folder in tomcat too but still it is not working.

Error1 with index.xhtml to url:

XML Parsing Error: no element found
Location: http://www.touchegolfmart.com/index.xhtml
Line Number 1, Column 1:

Erro2 with out index.xhtml to url

File not found
Firefox can't find the file at http://www.touchegolfmart.com/.

my web.xml file is


<?xml version="1.0" encoding="UTF-8"?>


   <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>
 <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>index.xhtml</welcome-file>
   </welcome-file-list>
</web-app>

Context path in server.xml in conf folder of tomcat is:

 <Host name="touchegolfmart.com" appBase="/home/rathan">
      <Alias>www.touchegolfmart.com</Alias> 
      <Context path="" reloadable="true" docBase="public_html" debug="1"/>
     <!-- <Context path="/manager" debug="0" privileged="true"
          docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
      </Context>-->
   </Host>

Folder structure is: index.jsp
WEB-INF/classes
WEB-INF/lib
WEB-INF/faces-config.xml
WEB-INF/web.xml
WEB-lib/lib/jsf-api.jar,jsf-impl.jar,jstl.jar,standard.jar.
META-INF/context.xml

2
you need not only web.xml also some libraries jsf-api, jsf-impl and etc. There are a lot of examples. Look at this one roseindia.net/java/javaee6/JSF2.0SimpleExample.shtmlDarka
Sorry to mention,that i also added jsf-api.jar jsf-impl.jar,jstl.jar and standard.jar to lib folderVijay Krish
have faces-config.xml file? And what is your folder structure?Darka
faces-config.xml is there and also web.xml is updated in the postVijay Krish
@Darka: roseindia.net is world's worst Java EE resource and is full of bad practices and misleading code examples. Please never recommend that site to starters. It would only confuse them and make the real code end up in a disaster.BalusC

2 Answers

0
votes

I quickly put some example. Created T folder in webapp folder. Created file hello.xhtml:

<?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:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>JSF 2.0 Hello World</title>
    </h:head>
    <h:body>
        <h3>JSF 2.0 Hello World Example</h3>
        <h:form>

            <h:commandButton value="Click" action="welcome"></h:commandButton>
        </h:form>
    </h:body>
</html>

Created file welcome.xhtml:

<?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:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>JSF 2.0 Hello World</title>
    </h:head>
    <h:body bgcolor="white">
        <h2>JSF 2.0 Hello World Example</h2>
    </h:body>
</html>

After this created folder WEB-INF in T folder and created 2 files: web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>JSFHelloWorld</display-name>
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>faces/hello.xhtml</welcome-file>
  </welcome-file-list>
  <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>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
</web-app>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    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"
    version="2.0">

</faces-config>

also in T/WEB-INF folder created folder lib, which has jsf-api-2.1.12.jar, jsf-impl-2.1.12.jar, jstl-1.2.jar files.

This works, but I don't used any POJO.

0
votes

Instead of placing the files in the appBase folder manually, place a .war file and extract it through jar command then restarting the tomcat made my application work.