1.寮鍙戠幆澧?
聽 聽涓嶦clipse涓婼truts鐨勫紑鍙戠被浼鹼紝瀹夎濂紼clipse鍜孴omcat涔嬪悗錛岃繕闇瑕佷袱涓彃浠訛細tomcat 鎻掍歡鍜孞SF鎻掍歡錛堝鏋滅浉鍏蟲彃浠惰繕娌℃湁瀹夎錛夛紝浠ヤ笅鏄浉鍏充笅杞藉湴鍧錛?
聽 聽 Eclipse SDK錛?
聽 聽 聽 聽
http://www.eclipse.org/downloads/index.php聽
聽 聽 JSF:
聽 聽 聽https://sourceforge.jp/projects/amateras/files/ 聽
聽 聽 聽 FaceIDE+htmlEditor錛宧tmlEditer涔熸槸蹇呰鐨?
聽 聽 Tomcat :
聽 聽 聽 聽 聽
http://www.sysdeo.com/eclipse/tomcatplugin聽
聽 聽 Plugin Search:
聽 聽 聽 聽 聽
http://eclipse-plugins.2y.net/eclipse/search.jsp聽
聽 聽鎻掍歡鐨勫畨瑁呭拰閰嶇疆鏈夐棶棰樿鐩存帴Google銆?
2.寮濮?
聽 聽 鍏ラ棬鍢涳紝鎴戜滑灝辨壘涓涓渶綆鍗曠殑Login灝卞彲浠ヤ簡
聽 聽 鏂板緩Tomcat project
聽 聽 鍔犲叆JSF鏀寔
聽 聽 鏂板緩涓涓狹anagedBean錛?
/**
聽*
聽*/
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欏甸潰錛宭ogin.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錛?
聽 聽 聽 聽 <h3>welcome JavaServer Faces</h3>
聽 聽 </f:view>
</body>
</html>
聽 聽 聽緙栬緫WEB錛岻NF/lib涓嬬殑faces錛峜onfig.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>
聽 聽 聽 聽鏈鍚庢槸璧勬簮鏂囦歡
# --login.jsp--
header=Welcom
namePromt=Name:
passwordPromt=Password:
amountPromt=Amount:
datePromt=Date:
submitPromt=Submit
resetPromt=Reset
footer=Thank you!
3.嫻嬭瘯
鍦╰est宸ョ▼涓夋嫨tomcat project錛?gt;Update context definition
鐒跺悗榪愯Tomcat
http://127.0.0.1:8080/jsfTest/login.jsf