Struts+Spring+Hibernate練習(完整)
摘自:http://www.blogjava.net/oksonic/archive/2005/11/06/18370.html
[@more@]prompt.password=User Password
增加以下內容
prompt.password=登入密碼
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
validate="true" type="com.test.struts.action.LoginAction" />
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
DynaValidatorForm loginForm = (DynaValidatorForm) form;
String username=loginForm.getString("username");
String password=loginForm.getString("password");
if(username.equals("test")||password.equals("test")){
return mapping.findForward("indexGo");
}else{
return mapping.getInputForward();
} }
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
validate="true"
type="com.test.struts.action.LoginAction" />
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
validate="true"
type="org.springframework.web.struts.DelegatingActionProxy" />
0000ff">">
`ID` int(11) NOT NULL auto_increment,
`USERNAME` varchar(50) NOT NULL default '',
`PASSWORD` varchar(50) NOT NULL default '',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
UserDAO.java
public interface UserDAO {
public abstract boolean isValidUser(String username, String password);
}
UserDAOImp.java
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.test.Hibernate.SessionFactory;
public class UserDAOImp extends HibernateDaoSupport implements UserDAO {
private SessionFactory sessionFactory;
private static String hql = "from User u where u.username=? ";
public boolean isValidUser(String username, String password) {
List userList = this.getHibernateTemplate().find(hql, username);
if (userList.size() > 0) {
return true;
}
return false;
}
}
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
public class LoginAction extends Action {
private UserDAO userDAO;
return userDAO;
}
this.userDAO = userDAO;
}
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorForm loginForm = (DynaValidatorForm) form;
// TODO Auto-generated method stub
String username = (String) loginForm.get("username");
String password = (String) loginForm.get("password");
loginForm.set("password", null);
if (userDAO.isValidUser(username,password)) {
return mapping.findForward("indexGo");
} else {
return mapping.getInputForward();
} }
綠色字型為修改部份
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/778728/viewspace-927522/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle-hr表查詢命令練習(超完整的select命令大全)Oracle
- 求助於struts+spring+hibernateSpring
- [摘]Struts+Spring+Hibernate整合Spring
- 新手練習:Python練習題目Python
- MYSQL練習1: DQL查詢練習MySql
- sql 練習SQL
- MySQL練習MySql
- latex練習
- ddl練習
- MySQ練習
- struts+spring+hibernate感悟(轉載)Spring
- oracle基礎練習11-15章 索引維護、資料庫完整性等Oracle索引資料庫
- U7-11課綜合練習+12課階段測評練習——複習練習題目
- Scala學習(三)練習
- Scala學習(四)練習
- Scala學習(五)練習
- Scala學習(六)練習
- Scala學習(七)練習
- struts+spring+hibernate找不到bean....SpringBean
- nginx配置練習Nginx
- python練習Python
- mysql練習題MySql
- Java方法練習Java
- MYSQL練習二MySql
- JS原生練習JS
- TypeScript 練習題TypeScript
- C++練習C++
- java練習題Java
- pl/sql練習SQL
- 入門練習
- Find命令練習
- pl/sql 練習SQL
- SQL 練習題SQL
- 課堂練習
- 隨堂練習
- SQL練習題SQL
- 【THM】dogcat練習GC
- 選單練習