Posted on 2007-07-02 16:08
Java.net 閱讀(794)
評論(1) 編輯 收藏 所屬分類:
JSF
看了一上午的JSF,下午做了一個例子..很簡單,一共兩個頁面index.jsp和welcome.jsp
index.jsp主要源碼
<f:view>
<h:form>
<h3>In put your name:</h3>
Name:<h:inputText value="#{personBean.name}"></h:inputText>
<h:commandButton value="Login" action="login"></h:commandButton>
</h:form>
</f:view>
welcome.jsp主要源碼
<f:view>
<h:outputText value="#{personBean.name}"></h:outputText> Hello!!
<h3>Welcome to JavaServerFace</h3>
</f:view>
在index.jsp中錄入姓名,然后在welcome中顯示出來..
開發環境為Eclipse3.3版本.安裝了Eclipse用于開發J2EE的插件WPT2.0...非常好用,不用再去用MyEclipse了...
在Eclipse的Window->Preference->Server->Installed Runtimes中安裝一個服務器,本例使用的Tomcat6.0.切換到Eclipse的J2EE視圖,可以看到新建的Server已經在右下的server頁簽看到了...環境準備好后,開始建立人員的Bean
PersonBean代碼:
package com.xzuf.jsf;
import java.io.Serializable;
/**
* PersonBean
* @author xzgf <a href='mailto:javac_oracle@163.com'>javac_oracle@163.com</a>
* @create 2007-7-2
*
*/
public class PersonBean implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
打開自動生成的faces-config.xml,Eclipse會用默認的圖形界面打開,可以方便的配置Bean管理,頁面導航等信息...增加一個作用域為session的bean管理, 并設置index.jsp->welcome.jsp的導航...啟動服務器,打開頁面...完成..