1,整合Struts2
a)导入struts的jar包
struts2-core-2.1.6.jar xwork-2.1.2.jar ognl-2.6.11.jar freemarker-2.3.13.jar commons-logging-1.1.jar commons-fileupload-1.2.1.jar
b)将struts.xml文件拷贝到src目录下
c)在web.xml里配置struts的核心过滤器
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2,整个Spring
a)导入Spring的jar包 spring.jar commons-logging.jar
b)将applicationContext.xml文件拷贝到WEB-INF目录下
c)在web.xml里配置spring的监听器
<!-- 配置spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
d)添加spring与struts2整合的插件 struts2-spring-plugin-2.1.6.jar
3,编写代码测试
登录页面login.jsp
<body>
<form action="login" method="post">
USERNAME:<input type="text" name="username" /><br>
PASSWORD:<input type="password" name="password" /><br>
<input type="submit" value="登录">
</form>
</body>
登录成功页面 success.jsp
<body>
登录成功!
</body>
LoginDao业务接口
package com.itmyhome.actioin;
interface LoginDao {
public boolean login(String username,String password);
}
LoginDaoImpl业务接口实现
package com.itmyhome.actioin;
public class LoginDaoImpl implements LoginDao {
public boolean login(String username, String password) {
// TODO Auto-generated method stub
if("zhangsan".equals(username)&&"123".equals(password)){
return true;
}else{
return false;
}
}
}
LoginAction
package com.itmyhome.actioin;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private String username;
private String password;
private LoginDao loginDao; //此DAO交给spring来处理