struts2+spring框架搭建

今天对原来ssm框架进行升级至struts2.3+spring4.3,将框架搭建细节做个记录以备后续查看,废话不多少,进入正题。
**

struts2.3

从官网下载struts2.3jar包

这里写图片描述
struts.xml配置文件

<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.locale" value="zh_CN" />
<constant name="struts.multipart.maxSize" value="629145600" />

<package name="struts" namespace="/" extends="struts-default">

    <action name="login_*" class="userAction" method="{1}" >
       <result>index.jsp</result>
    </action>
</package>


标签中class属性不是必须的,有一下几种情况:
1、没有配置class属性,核心控制器会将Actionsuppot作为默认action,并默认调用该action的execute方法。
2、配置了class属性但没有配置method属性,如果配置的action继承了ActionSupport,则执行ActionSupport的execute方法;如果配置的action没继承ActionSupport,action中也没有自己的execute方法,则抛出异常。
3、即配置了class也配置了method,执行配置的action中的menthod方法。

web.xml
这里写图片描述
struts2.0-struts2.1.2核心过滤器是FilterDispatcher,从struts2.1.3开始换成StrutsPrepareAndExecuteFilter。
struts.xml默认在classpath下,我放在config目录下,需要在web.xml配置中显示设置,并且显示设置struts默认的配置文件路径(struts-default.xml,struts-plugin.xml)
Action

public class UserAction extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
此时struts框架已搭建完成。

集成spring

下载spring所需jar
这里写图片描述

web.xml
配置spring的监听器,默认加载WEB-INF/applicationContext.xml
修改路径和文件名称需要重新配置。

contextConfigLocation
classpath:config/app-*.xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

spring-datasource
这里写图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值