后面的就只有DAO层和Serivce层了,这二个类很简单的了。
DAO:
/*
* Created on 2007-9-13
*
* Copyright (c) 2006 Prudential Services Asia. All Rights Reserved.
*
* This software is the confidential and proprietary information of Prudential Services Asia. ("Confidential
* Information"). You shall not disclose such Confidential Information and shall use it only in accordance with the
* terms of the license agreement you entered into with Prudential.
*/
package com.jsf.dao;
import com.jsf.bean.UserBean;
/**
* LoginDao
*
* @author Shuai.yang
* @date 2007-9-13
* @version 1.0
*/
public class LoginDao {
private UserBean user;
/**
* @return Returns the user.
*/
public UserBean getUser() {
return user;
}
/**
* @param user
* The user to set.
*/
public void setUser(UserBean user) {
this.user = user;
}
public boolean checkUser() {
boolean reslut = false;
if (user.getUserName().equals("a") && user.getUserPwd().equals("a")) {
reslut = true;
}
return reslut;
}
}
通过XML配置文件就可以把UserBean注入到DAO层来进行操作了。。。
同样的可以把DAO注入到Service层去进行业务逻辑操作:
Service:
/*
* Created on 2007-9-10
*
* Copyright (c) 2006 Prudential Services Asia. All Rights Reserved.
*
* This software is the confidential and proprietary information of Prudential Services Asia. ("Confidential
* Information"). You shall not disclose such Confidential Information and shall use it only in accordance with the
* terms of the license agreement you entered into with Prudential.
*/
package com.jsf.service;
import com.jsf.dao.LoginDao;
/**
* LoginService
*
* @author Shuai.yang
* @date 2007-9-10
* @version 1.0
*/
public class LoginService {
private LoginDao loginDao;
/**
* @return Returns the loginDao.
*/
public LoginDao getLoginDao() {
return loginDao;
}
/**
* @param loginDao
* The loginDao to set.
*/
public void setLoginDao(LoginDao loginDao) {
this.loginDao = loginDao;
}
/**
*
* @return
*
* @author Shuai.yang
* @date 2007-9-10
*/
public String loginAction() {
if (loginDao.checkUser()) {
return "welcome";
}
return "false";
}
}
最后是web.xml:
<?xml version="1.0"?>
<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">
<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>*.face</url-pattern>
</servlet-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>/page/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
-----------------------------------------------------------------
到此所有的主要代码都已完了。。。