一、JSF开发环境 使用myeclipse的功能,添加相关lib到classpath。 或者从sun的官方网站下载相关lib。http://java.sun.com/javaee/javaserverfaces/download.html二、JSP页面 index.jsp
welcome.jsp
三、Bean UserBean .java package com.test.jsf.bean;
public class UserBean {
private String name;
private String password;
// PROPERTY: name public String getName() { return name; }
public void setName(String newValue) { name = newValue; }
// PROPERTY: password public String getPassword() { return password; }
public void setPassword(String newValue) { password = newValue; } public String check() { name = "wxf"; return "success"; //return SUCCESS; }}四、faces-config<?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 > <navigation-rule> <from-view-id>/login/index.jsp</from-view-id> <navigation-case> <from-outcome>login</from-outcome> <to-view-id>/login/welcome.jsp</to-view-id> </navigation-case> </navigation-rule> <managed-bean> <managed-bean-name>user</managed-bean-name> <managed-bean-class> com.test.jsf.bean.UserBean </managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean>
</faces-config>五、web.xml<?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" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value>/WEB-INF/faces-config.xml</param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping></web-app>
六、测试 http://localhost:8080/jsf/login/index.faces注意,调用jsp页面时一定要使用faces,结尾,否则jsf的标签将无法识别
posted on 2007-04-26 12:56 风人园 阅读(599) 评论(0) 编辑 收藏 所属分类: JSF
Powered by: BlogJava Copyright © 风人园