shh环境配置——Spring与struts整合

来源:互联网 发布:时间碎片是什么软件 编辑:程序博客网 时间:2024/06/16 03:13

首先加入Struts包,其次配置web.xml,再者写action类,接着配置action.xml,然后引入Struts.文件配置。最后发布测试。

第一步引入包

第二步

1.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>*.action</url-pattern>
</filter-mapping>

2.spring监听器。

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
3.引入配置action.xml

<bean id="userAction" class="cn.itcast.web.UserAction" scope="prototype">
<property name="userService" ref="userService"></property>

注意设置Scope=“prototype”

4.配置Struts.xml

<struts>
  <!-- 常量配置 -->
  <!-- 1.struts 使用简单样式主题-->
  
<package name="user" extends="struts-default">
     <action name="user_*" class="userAction" method="{1}">
     <result name="success">/index.jsp</result>
     </action>
</package>




</struts>

0 0
原创粉丝点击