public String execute(){
if(loginDao.login(username, password)){
return "success";
}else{
return "input";
}
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public LoginDao getLoginDao() {
return loginDao;
}
public void setLoginDao(LoginDao loginDao) {
this.loginDao = loginDao;
}
}
struts.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="com.itmyhome.actioin.LoginAction">
<result name="success">/success.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
<!-- Add packages here -->
</struts>
applicationContext.xml配置文件
<bean id="loginDao" class="com.itmyhome.actioin.LoginDaoImpl" />
<!-- 可注释 -->
<bean id="loginAction" class="com.itmyhome.actioin.LoginAction">
<property name="loginDao" ref="loginDao" />
</bean>
部署,启动tomcat 输入"zhangsan","123" 跳转到success.jsp 整合成功
摘自 itmyhome的专栏