Struts2与Spring整合,实现登录效果

来源:互联网 发布:淘宝店铺引进流量 编辑:程序博客网 时间:2024/06/18 05:26
1.导jar包(第一部分:struts2   第二部分spring  第三部分 struts2-spring-plugin-2.3.32.jar)

2.创建两个配置文件 struts.xml ,applicationContext.xml

3.在web.xml文件中添加第一个 spring监听  (spring-web) 第二部分 struts2过滤器(contextConfigLocation是配置applicationContext.xml路径,不写我们可以将它复制放在WEB-INF文件夹下)

4.写xml登录页面(success.jsp与error.jsp就不在这里写了);写action(继承 ActionSupport)

5.实例化action(在applicationContext.xml中)
<bean id="loginAction" class="org.hp.action.LoginAction"></bean>

6. 修改struts.xml配置(class调用applicationContext.xml中class对应的id)

<struts>
     <package name="struts" namespace="/" extends="struts-default">
        <action name="dologin" class="loginAction" method="login">
            <result name="success">success.jsp</result>
            <result name="error">error.jsp</result>
        </action>
    </package>
</struts>
总结:到此我们就完成了Struts2与Spring的简单整合,实现登录的demo效果!!!