今天对原来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