1.å¼€å‘环å¢?
  与Eclipse下Struts的开å‘ç±»ä¼û|¼Œå®‰è£…好Eclipseå’ŒTomcat之åŽåQŒè¿˜éœ€è¦ä¸¤ä¸ªæ’ä»Óž¼štomcat æ’äšgå’ŒJSFæ’äšgåQˆå¦‚果相å…Ïx’件还没有安装åQ‰ï¼Œä»¥ä¸‹æ˜¯ç›¸å…³ä¸‹è½½åœ°å€åQ?
  Eclipse SDKåQ?
   Â
http://www.eclipse.org/downloads/index.phpÂ
  JSF:
   https://sourceforge.jp/projects/amateras/files/ Â
   FaceIDE+htmlEditoråQŒhtmlEditer也是必è¦çš?
  Tomcat :
    Â
http://www.sysdeo.com/eclipse/tomcatpluginÂ
  Plugin Search:
    Â
http://eclipse-plugins.2y.net/eclipse/search.jspÂ
  æ’äšg的安装和é…置有问题请直接Googleã€?
2.开�
  入门嘛,我们ž®±æ‰¾ä¸€ä¸ªæœ€½Ž€å•çš„Loginž®±å¯ä»¥äº†
  新å¾Tomcat project
Â Â åŠ å…¥JSF支æŒ
  新å¾ä¸€ä¸ªManagedBeanåQ?
/**
 *
 */
package com.jsf;
/**
 * @author lzy
 *
 */
public class UserBean {
private String name;
  private String password;
public String verify() {
   if(this.name.equals("name")&&this.password.equals("password"))
  Â
    return "failure";
  else
    return "success";
}
Â
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @return Returns the password.
*/
public String getPassword() {
return password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password) {
this.password = password;
}
}
   新å¾ä¸¤ä¸ªJSP™åµé¢åQŒlogin.jsp,welcom.jsp
login.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="
http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="
http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="
http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="
http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<link href="main.css" rel="stylesheet"/>
<title></title>
</head>
<body>
  <f:view>
  <f:loadBundle basename="com.jsf.MessageResources" var="msgs"></f:loadBundle>
 Â
    <h:form>
    <h:panelGrid columns="3" headerClass="header" rowClasses="evenRow,oddRow">
    <f:facet name="header" >
    <h:outputText value="#{msgs.header}"/>
    </f:facet>
   Â
    <h:outputText value="#{msgs.namePromt}"></h:outputText>
    <h:inputText id="name"  required="true" value="#{user.name}">
    <f:validateLength minimum="2" maximum="10"></f:validateLength>
    </h:inputText>
    <h:message for="name" errorClass="errors"/>
   Â
   Â
    <h:outputText value="#{msgs.passwordPromt}"></h:outputText>
   Â
    <h:inputSecret id="password" value="#{user.password}" required="true" redisplay="true">
    <f:validateLength minimum="2"></f:validateLength>
    </h:inputSecret>
    <h:message for="password"/>
   Â
   Â
       <f:facet name="footer" >
    <h:outputText value="#{msgs.footer}"/>
    </f:facet>
    </h:panelGrid>     Â
      <h:commandButton value="#{msgs.submitPromt}" action="#{user.verify}"/>
      <h:commandButton value="#{msgs.resetPromt}" type="reset"/>
    </h:form>
  </f:view>
</body>
</html>
welcome.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="
http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="
http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<title></title>
</head>
<body>
  <f:view>
    <h:outputText value="#{user.name}"/>  is a good boyåQ?
    <h3>welcome JavaServer Faces</h3>
  </f:view>
</body>
</html>
   ¾~–辑WEBåQINF/lib下的facesåQconfig.xml
struts-config.xml
<?xml version="1.0"?>
<!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>
<navigation-rule>
    <from-view-id>/login.jsp</from-view-id>
    <navigation-case>
      <from-outcome>success</from-outcome>
      <to-view-id>/welcome.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
      <from-outcome>failure</from-outcome>
      <to-view-id>/login.jsp</to-view-id>
    </navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.jsf.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
Â Â Â Â æœ€åŽæ˜¯èµ„æºæ–‡äšg
# --login.jsp--
header=Welcom
namePromt=Name:
passwordPromt=Password:
amountPromt=Amount:
datePromt=Date:
submitPromt=Submit
resetPromt=Reset
footer=Thank you!
3.‹¹‹è¯•
在test工程ä¸é€‰æ‹©tomcat projectåQ?gt;Update context definition
然厘q行Tomcat
http://127.0.0.1:8080/jsfTest/login.jsf