java ssh struts2版本升级

一.替换jar包.我项目只用到了这些,不全的请自己下载struts2.3.15.1的所有lib包,自行替换

删除的包有:
commons-lang-2.4.jar
ognl-2.6.11.jar
struts2-codebehind-plugin-2.0.11.1.jar
struts2-core-2.0.11.1.jar
struts2-jasperreports-plugin-2.0.11.1.jar
struts2-spring-plugin-2.0.11.1.jar
xwork-2.0.4.jar

新增的包有:
commons-lang3-3.1.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.15.1.jar
struts2-jasperreports-plugin-2.3.15.1.jar
struts2-spring-plugin- 2.3.15.1.jar
xwork-core-2.3.15.1.jar


二.替换代码
分别查找:
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import com.opensymphony.xwork2.util.TypeConversionException;


分别替换为:
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.opensymphony.xwork2.conversion.TypeConversionException;


三.web.xml
查找:
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

替换为:
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
		<param-name>actionPackages</param-name>
		<param-value>com.mycompany.myapp.actions</param-value>
</init-param>


查找并删除:
<filter>
		<filter-name>struts-cleanup</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
		<filter-name>struts-cleanup</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
</filter-mapping>


FilterDispatcher是struts2.0.x至2.1.2的核心过滤器
StrutsPrepareAndExecuteFilter在2.1.3开始代替FilterDispatcher

ActionContextCleanUp在2.1.3之后的版本不需要配置

不删除ActionContextCleanUp的配置,项目会在Console中报warning

四.struts.xml
如果在struts配置文件中有使用的redirect-action话
需要将redirect-action替换为redirectAction

如果自定义了拦截器的话
需要把带"-"的,都把"-"去掉,并且把"-"后边的第一个字母大写
如:
servlet-config改为:servletConfig
scoped-model-driven改为: scopedModelDriven
model-driven改为: modelDriven


五. JSP EL表达式
如果在页面中用了struts2标签,并且在struts2标签中使用了EL表达式
那么就要把EL表达式改成OGNL表达式,否则会报错
如:
<s:property value="${printCount}"/>
要改成
<s:property value="#request.printCount"/>

printCount是Action中局部变量,被放到了request作用域中

public String print(){
long  printCount  = 5;//已打印发票数

getRequest().setAttribute(" printCount",  printCount);

return SUCCESS;
}

如果EL表示是没有放到struts标签中的话,还是可以使用的
如:
<title>本页面已打印${printCount}次</title>

从struts2.0.11开始,不再支持JSP EL表达式了
官方说明:
Struts 2.0.10 corrected a serious security flaw in the Struts 2 tags where using JSP EL expressions could allow malicious OGNL expressions through. All users are encouraged to upgrade to Struts 2.0.11. Note that existing pages that utilize JSP EL expressions with Struts 2 tags will no longer work as of this release.


注意:
jsp文件放到static下,会导致访问不到

黑色头发:http://heisetoufa.iteye.com

你可能感兴趣的:(struts,EL,升级,Ognl,struts2.3.15.1)