整合Spring,换句话说,也就是让spring的IOC功能为我们的struts action注入逻辑组件
首先需要加载struts2-spring-plugin-2.0.6.jar这个包,这个是关键,他可以帮我们把struts2和spring仅仅整合在一起
首先是web.xml
其次是struts2.xml
最关键的是bean.xml,完成为struts2 action的注入
LoginAction
MyService及实现
struts.properties
struts.i18n.encoding=gb2312
login.jsp
<%@ page contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>登录页面</title>
</head>
<body>
<form action="login.action" method="post">
<table align="center">
<caption><h3>用户登录</h3></caption>
<tr>
<td>用户名:<input type="text" name="username"/></td>
</tr>
<tr>
<td>密 码:<input type="text" name="password"/></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="登录"/><input type="reset" value="重填" /></td>
</tr>
</table>
</form>
</body>
</html>
welcome.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>成功页面</title>
</head>
<body>
您已经登录!
<s:property value="username"/>
<s:property value="tip"/>
</body>
</html>
error.jsp
<%@ page language="java" contentType="text/html; charset=GBK"%>
<html>
<head>
<title>错误页面</title>
</head>
<body>
您不能登录!
</body>
</html>