【IT168 技术文档】
花了2个小时终于配置好struts2.0.6+spring2.0.3+hibernane3,为自己庆祝一下,分享一下经验
一、配置Struts2
跟webwork配置基本一致,主要是struts2.properties和struts.xml 2个配置文件,我的struts2.properties如下配置:
struts2.properties
struts.tag.altSyntax = true
struts.devMode = true
### These can be used to set the default HTTP and HTTPS ports
struts.url.http.port = 80
#webwork.url.https.port = 443
### This can be used to set your locale and encoding scheme
struts.custom.i18n.resources=ApplicationResources
struts.locale=zh_CN
struts.i18n.encoding=utf-8
# uses javax.servlet.context.tempdir by default
struts.multipart.parser=com.opensymphony.webwork.dispatcher.multipart.PellMultiPartRequest
#struts.multipart.saveDir=tmp
struts.multipart.saveDir=/tmp
struts.multipart.maxSize=512000000
struts.configuration.xml.reload=true
struts.objectFactory = spring
struts.tag.altSyntax = true
struts.devMode = true
### These can be used to set the default HTTP and HTTPS ports
struts.url.http.port = 80
#webwork.url.https.port = 443
### This can be used to set your locale and encoding scheme
struts.custom.i18n.resources=ApplicationResources
struts.locale=zh_CN
struts.i18n.encoding=utf-8
# uses javax.servlet.context.tempdir by default
struts.multipart.parser=com.opensymphony.webwork.dispatcher.multipart.PellMultiPartRequest
#struts.multipart.saveDir=tmp
struts.multipart.saveDir=/tmp
struts.multipart.maxSize=512000000
struts.configuration.xml.reload=true
struts.objectFactory = spring
struts.xml 就是配置action了,由于设定了struts.objectFactory = spring,因此struts2会自动将action转为spring的bean,struts.xml可以直接配置我们的action路径,在action中我们只需要设置某个service文件的set方法即可调用事务管理bean。
struts.xml
<!--sp-->xml version="1.0" encoding="UTF-8" ?> <!--CTYPE struts PUBLIC </sp--> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file="struts-default.xml" /> <package name="default" extends="struts-default"> <default-interceptor-ref name="completeStack" /> <global-results> <result name="login" type="redirect">login!default.actionresult> <result name="unauthorized">unauthorized.jspresult> global-results> <action name="login" class="com.baseframe.action.LoginAction"> <result name="input">login.jspresult> <result name="success">main.jspresult> <result name="error">login.jspresult> action> <action name="logout" class="com.baseframe.action.LogoutAction"> <result name="success">login.jspresult> action> package> struts>