Quickly build a JSF environment...

Source: Internet
Author: User
The first step is to place the jsf jar file in the correct position...
Directory/File Description
Tutorial Project catalog
/Ant Ant Script directory. The default value is build. xml.
/Src Java source file, directory where the. properties file is located.
/Public_html The directory where dynamic web pages such as JSP and JSF are located.
WEB-INF The configuration files and class libraries used for running web applications are invisible to browsers.
/Classes The output directory of the compiled Java source file.
/Lib The class library that the project depends on.
Jsf-impl.jar
Jsf-api.jar
JSF 1.1 class library, of course, there are some jar files of the Jakarta common class library!
Web. xml Web application deployment configuration file
Faces-config.xml JSF configuration file
Pages JSP, JSF, and HTML

Then, modify the web. XML, please note that if the web. if the XML format is version = "2.4", you do not need to display the TLD file used by the specified taglib... we only need to add the definition related to the jsf servlet:

<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version = "2.4">
<Description> J2EE Tutorial Project </description>
<Display-Name> tutorial </display-Name>
<Session-config>
<Session-timeout> 30 </session-timeout>
</Session-config>
<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>
<Welcome-file-list>
<Welcome-file> index. jsp </welcome-file>
</Welcome-file-list>
</Web-app>

Then add a WEB-INF under the/faces-config.xml with the following content:

<? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE faces-config PUBLIC "-// Sun Microsystems, Inc. // DTD JavaServer Faces Config 1.1 // EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<Faces-config xmlns = "http://java.sun.com/JSF/Configuration">
<Managed-bean>
<Managed-bean-name> userBean </managed-bean-name>
<Managed-bean-class> tutorial. beans. UserBean </managed-bean-class>
<Managed-bean-scope> request </managed-bean-scope>
<Managed-property>
<Property-name> username </property-name>
<Property-class> java. lang. String </property-class>
<Value> Shark Wang </value>
</Managed-property>
</Managed-bean>
<Navigation-rule>
<From-view-id>/pages/login. jsp </from-view-id>
<Navigation-case>
<From-outcome> greeting </from-outcome>
<To-view-id>/pages/greeting. jsp </to-view-id>
</Navigation-case>
</Navigation-rule>
</Faces-config>

After completing the above steps, JSF will not be automatically started. We need a JSP to start the JSF... index. jsp Code as follows:

<% @ Page pageEncoding = "UTF-8" %>
<Jsp: forward page = "/pages/login. faces"/>

Start to run... find a dizzy error:

ApplicationDispatcher [/Tutorial]: Servlet. service () for servlet Faces Servlet threw exception
Java. lang. NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
At com. sun. faces. application. ViewHandlerImpl. renderView (ViewHandlerImpl. java: 140)
At com.sun.faces.lifecycle.RenderResponsePhase.exe cute (RenderResponsePhase. java: 87)
At com. sun. faces. lifecycle. LifecycleImpl. phase (LifecycleImpl. java: 200)
At com. sun. faces. lifecycle. LifecycleImpl. render (LifecycleImpl. java: 117)
At javax. faces. webapp. FacesServlet. service (FacesServlet. java: 198)

Originally, JSF still relied on jstl ~~~ Not mentioned in the jsf document. .. depressing. After jstl's jstl. jar and standard. jar are added, everything will be okay!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.