日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Struts2 常量配置

發(fā)布時(shí)間:2025/3/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Struts2 常量配置 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
經(jīng)過(guò)前幾講的介紹,我想大家對(duì)struts2有了初步的了解,下面讓我來(lái)講講struts2中常量的用法和使用(常量的默認(rèn)配置struts2-core-2.x.x.x/org/apache/struts2/default.properties文件里)。

一.常量配置:

???????? 要用常量,首先要通過(guò)配置來(lái)實(shí)現(xiàn),常量可以在下面多個(gè)文件中進(jìn)行定義,struts2載常量的搜索順序如下,后面的設(shè)置可以覆蓋前面的設(shè)置:
??? default.properties文件
??? struts-default.xml
??? struts-plugin.xml
??? struts.xml
??? struts.properties
??? web.xml

???????? 注意:

1.?????? 之所以使用struts.propreties文件配置,是因?yàn)闉榱吮3峙cWebWork的向后兼容

2.?????? 在實(shí)際開發(fā)中,在web.xml中配置常量相比其他兩種,需要更多的代碼量,會(huì)降低了web.xml的可讀性

3.?????? 通常推薦在struts.xml文件中配置struts2的常量,而且便于集中管理

二、常量詳解:????

(1)struts.i18n.encoding=UTF-8?????? 指定默認(rèn)編碼??? ??? 用法: <constant name="struts.i18n.encoding" value="UTF-8" />? (2)struts.action.extension指定Struts 2處理的請(qǐng)求后綴,默認(rèn)值是action,即所有匹配*.action的請(qǐng)求都由Struts2處理,如果用戶需要指定多個(gè)請(qǐng)求后綴,則多個(gè)后綴之間以英文逗號(hào)(,)隔開???? 用法:<constant name="struts.action.extension" value="do" />? 或者???? <constant name="struts.action.extension" value="do,action" />? (3)struts.configuration.xml.reload???? 當(dāng)struts的配置文件修改后,系統(tǒng)是否自動(dòng)重新加載該文件,默認(rèn)值為false(生產(chǎn)環(huán)境下使用),開發(fā)階段最好打開 ????用法:<constant name="struts.configuration.xml.reload" value="true" /> ? (4)struts.devMode? ???????? 開發(fā)模式下使用,默認(rèn)為false,設(shè)置成true,這樣可以打印出更詳細(xì)的錯(cuò)誤信息,有助于查找到錯(cuò)誤,在開發(fā)的時(shí)候建議開啟,項(xiàng)目發(fā)布之后改成false <constant name="struts.devMode" value="true" />? (5)struts.multipart.parser ?????該屬性指定處理 MIME-type multipart/form-data,文件上傳方式,有三種方式cos、pell 、jakarta;struts2默認(rèn)采用第三種方式,如果想用前兩種方式,需要去網(wǎng)上下載相應(yīng)jar包即可 ???用法: <constant name="struts.multipart.parser" value="cos" />? ???????? <constant name="struts.multipart.parser" value="pell" />? ???????? <constant name="struts.multipart.parser" value="jakarta" />? (6)struts.multipart.saveDir???? 指定上傳文件時(shí)的臨時(shí)目錄,默認(rèn)使用 javax.servlet.context.tempdir 用法:<constant name="struts.multipart.saveDir" value="/tmpuploadfiles" />? ????? (7)struts.multipart.maxSize???????? 該屬性指定Struts 2文件上傳中整個(gè)請(qǐng)求內(nèi)容允許的最大字節(jié)數(shù) 默認(rèn)為2M ????用法:<constant name="struts.multipart.maxSize" value="2097152" />? ? (8)struts.ui.theme? ?????默認(rèn)的視圖主題,可以為simple,xhtml或ajax??? 用法:<constant name="struts.ui.theme" value="simple" />? ???? (9)struts.serve.static.browserCache????? 設(shè)置瀏覽器是否緩存靜態(tài)內(nèi)容,默認(rèn)值為true(生產(chǎn)環(huán)境下使用),開發(fā)階段最好關(guān)閉 ????用法:<constant name="struts.serve.static.browserCache" value="false" />? (10)struts.enable.SlashesInActionNames 設(shè)置是否可以在action中使用斜線,默認(rèn)為false不可以,設(shè)置為true,可以使用 ????用法:<constant name="struts.enable.SlashesInActionNames" value="true" />? (11)struts.enable.DynamicMethodInvocation ??? 設(shè)置是否支持動(dòng)態(tài)方法調(diào)用,true為支持,false不支持. ????用法:<constant name="struts.enable.DynamicMethodInvocation" value="true" />? ?????下面是一些不常用的常量使用方法,需要了解一下:因?yàn)橹攸c(diǎn)是struts2的講解,所以與spring集成時(shí)用到的常量,在講spring時(shí)還將給大家重點(diǎn)講解,這里就不多說(shuō)了。? [java] view plaincopy
  • <!--???
  • ????????指定請(qǐng)求url與action映射器,默認(rèn)為org.apache.struts2.dispatcher.mapper.DefaultActionMapper???
  • ????-->????
  • ????<constant?name="struts.mapper.class"????
  • ????????value="org.apache.struts2.dispatcher.mapper.DefaultActionMapper"?/>????
  • ????<!--?是否允許使用表達(dá)式語(yǔ)法,默認(rèn)為true.?-->????
  • ????<constant?name="struts.tag.altSyntax"?value="true"?/>????
  • ????<!--?模板目錄?-->????
  • ????<cosntant?name="struts.ui.templateDir"?value="template"?/>????
  • ????<!--?設(shè)置模板類型.?可以為?ftl,?vm,?or?jsp?-->????
  • ????<cosntant?name="struts.ui.templateSuffix"?value="ftl"?/>????
  • ????<!--?定位velocity.properties?文件.?默認(rèn)velocity.properties?-->????
  • ????<cosntant?name="struts.velocity.configfile"?value="velocity.properties"?/>????
  • ????<!--?設(shè)置velocity的context.?-->????
  • ????<cosntant?name="struts.velocity.contexts"?value="...."?/>????
  • ????<!--?定位toolbox?-->????
  • ????<cosntant?name="struts.velocity.toolboxlocation"?value="...."?/>????
  • ????<!--?指定web應(yīng)用的端口?-->????
  • ????<cosntant?name="struts.url.http.port"?value="80"?/>????
  • ????<!--????
  • ????????該屬性指定Struts2應(yīng)用加載用戶自定義的屬性文件,該自定義屬性文件指定的屬性不會(huì)覆蓋????
  • ????????struts.properties文件中指定的屬性。如果需要加載多個(gè)自定義屬性文件,多個(gè)自定義屬性文????
  • ????????件的文件名以英文逗號(hào)(,)隔開。(也就是說(shuō)不要改寫struts.properties!)????
  • ????-->????
  • ????<constant?name="struts.custom.properties"????
  • ????????value="application,org/apache/struts2/extension/custom"?/>????
  • ???
  • ????<!--?指定加密端口?-->????
  • ????<cosntant?name="struts.url.https.port"?value="443"?/>????
  • ????
  • ????<!--?設(shè)置生成url時(shí),是否包含參數(shù).值可以為:?none,get?or?all?-->????
  • ????<cosntant?name="struts.url.includeParams"?value="get"?/>????
  • ???
  • ????<!--?設(shè)置要加載的國(guó)際化資源文件,以逗號(hào)分隔.?-->????
  • ????<cosntant?name="struts.custom.i18n.resources"?value="application"?/>????
  • ????<!--????
  • ????????對(duì)于一些web應(yīng)用服務(wù)器不能處理HttpServletRequest.getParameterMap(),?像????
  • ????????WebLogic,Orion,?and?OC4J等,須設(shè)置成true,默認(rèn)為false.????
  • ????-->????
  • ????<cosntant?name="struts.dispatcher.parametersWorkaround"?value="false"?/>????
  • ????
  • ????<!--?指定freemarker管理器?-->????
  • ????<cosntant?name="struts.freemarker.manager.classname"????
  • ????????value="org.apache.struts2.views.freemarker.FreemarkerManager"?/>????
  • ????
  • ????<!--?設(shè)置是否對(duì)freemarker的模板設(shè)置緩存,效果相當(dāng)于把template拷貝到?WEB_APP/templates.?-->????
  • ????<cosntant?name="struts.freemarker.templatesCache"?value="false"?/>????
  • ????
  • ????<!--?通常不需要修改此屬性.?-->????
  • ????<cosntant?name="struts.freemarker.wrapper.altMap"?value="true"?/>????
  • ????
  • ????<!--?指定xslt?result是否使用樣式表緩存.開發(fā)階段設(shè)為true,發(fā)布階段設(shè)為false.?-->????
  • ????<cosntant?name="struts.xslt.nocache"?value="false"?/>????
  • ????
  • ????<!--?設(shè)置struts自動(dòng)加載的文件列表.?-->????
  • ????<cosntant?name="struts.configuration.files"????
  • ????????value="struts-default.xml,struts-plugin.xml,struts.xml"?/>????
  • ????
  • ????<!--?設(shè)定是否一直在最后一個(gè)slash之前的任何位置選定namespace.?-->????
  • ????<cosntant?name="struts.mapper.alwaysSelectFullNamespace"????
  • ????????value="false"?/>????
  • <!--?spring?托管?與spring集成時(shí)需要用到?-->????
  • ????<constant?name="struts.objectFactory"?value="spring"?/>????
  • ????
  • ????<!--??指定加載struts2配置文件管理器,默認(rèn)為org.apache.struts2.config.DefaultConfiguration?,開發(fā)者可以自定義配置文件管理器,該類要實(shí)現(xiàn)Configuration接口,可以自動(dòng)加載struts2配置文件。????
  • ????-->????
  • ????<constant?name="struts.configuration"????
  • ????????value="org.apache.struts2.config.DefaultConfiguration"?/>????
  • ????
  • ????<!--?設(shè)置默認(rèn)的locale和字符編碼???國(guó)際化使用?-->????
  • ????<constant?name="struts.locale"?value="zh_CN"?/>????
  • ????<constant?name="struts.i18n.encoding"?value="UTF-8"?/>????
  • ????
  • ????<!--?指定Struts的工廠類?-->????
  • ????<constant?name="struts.objectFactory"?value="spring"></constant>????
  • ????
  • ????<!--????
  • ????????指定spring框架的裝配模式,裝配方式有:?name,?type,?auto,?and?constructor?(name????
  • ????????是默認(rèn)裝配模式)????
  • ????-->????
  • ????<constant?name="struts.objectFactory.spring.autoWire"?value="name"?/>????
  • ????
  • ????<!--?該屬性指定整合spring時(shí),是否對(duì)bean進(jìn)行緩存,值為true?or?false,默認(rèn)為true?-->????
  • ????<cosntant?name="struts.objectFactory.spring.useClassCache"?/>????
  • ????
  • ????<!--?指定類型檢查,包含tiger和notiger?-->????
  • ????<cosntant?name="struts.objectTypeDeterminer"?value="tiger"?/>??
  • 轉(zhuǎn)載于:https://www.cnblogs.com/jasontec/archive/2013/01/10/9601700.html

    總結(jié)

    以上是生活随笔為你收集整理的Struts2 常量配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。