3.3 Eclipse Ёᓔথ Struts 2
3.5 Struts 2 ⱘᴀ䜡㕂
3.5.3 struts.properties 䜡㕂᭛ӊ
Struts 2Ḛᶊ᳝ϸϾḌᖗ䜡㕂᭛ӊˈ݊Ё struts.xml ᭛ӊЏ㽕䋳䋷ㅵ⧚ᑨ⫼Ёⱘ Action
ᇘˈ ҹঞ 䆹 Action ࣙⱘ Result ᅮНㄝDŽ 䰸ℸП ˈStruts 2 Ḛᶊ䖬ࣙ ϔ Ͼ struts.properties᭛ӊˈ䆹᭛ӊᅮНњ Struts 2 Ḛᶊⱘ䞣ሲᗻˈᓔথ㗙ৃҹ䗮䖛ᬍব䖭ѯሲ ᗻᴹ⒵䎇ᑨ⫼ⱘ䳔∖DŽ
struts.properties᭛ӊᰃϔϾᷛޚⱘ Properties ᭛ӊˈ䆹᭛ӊࣙњ㋏߫ⱘ key-value ᇍ 䈵ˈ↣Ͼ key ህᰃϔϾ Struts 2 ሲᗻˈ䆹 key ᇍᑨⱘ value ህᰃϔϾ Struts 2 ሲᗻؐDŽ
struts.properties᭛ӊ䗮ᐌᬒ Web ᑨ⫼ⱘ WEB-INF/classes 䏃ᕘϟDŽᅲ䰙Ϟˈা㽕ᇚ 䆹᭛ӊᬒ Web ᑨ⫼ⱘ CLASSPATH 䏃ᕘϟˈStruts 2 Ḛᶊህৃҹࡴ䕑䆹᭛ӊDŽ
⦄ⱘ䯂乬ᰃˈstruts.properties ᭛ӊⱘાѯ key ᰃ᳝ᬜⱘ˛े struts.properties ᭛ӊ䞠
ࣙાѯሲᗻᰃ᳝ᬜⱘ Struts 2 ሲᗻDŽϟ䴶߫ߎњৃҹ struts.properties ЁᅮНⱘ Struts 2 ሲᗻDŽ
y struts.configuration˖䆹ሲᗻᣛᅮࡴ䕑 Struts 2 䜡㕂᭛ӊⱘ䜡㕂᭛ӊㅵ⧚఼DŽ䆹ሲᗻ ⱘ咬䅸ؐᰃ org.apache.Struts2.config.DefaultConfigurationˈ䖭ᰃ Struts 2 咬䅸ⱘ䜡㕂
᭛ӊㅵ⧚఼DŽབᵰ䳔㽕ᅲ⦄㞾Ꮕⱘ䜡㕂ㅵ⧚఼ˈᓔথ㗙߭ৃҹᅲ⦄ϔϾᅲ⦄
Configurationষⱘ㉏ˈ䆹㉏ৃҹ㞾Ꮕࡴ䕑 Struts 2 䜡㕂᭛ӊDŽ y struts.locale˖ᣛᅮ Web ᑨ⫼ⱘ咬䅸 LocaleDŽ
y struts.i18n.encoding˖ᣛᅮ Web ᑨ⫼ⱘ咬䅸㓪ⷕ䲚DŽ䆹ሲᗻᇍѢ໘⧚Ё᭛䇋∖খ᭄
䴲ᐌ᳝⫼ˈᇍѢ㦋পЁ᭛䇋∖খ᭄ؐˈᑨ䆹ᇚ䆹ሲᗻؐ䆒㕂Ў GBK 㗙 GB2312DŽ
㌑ 䡻 ᔧ 䆒 㕂 䆹 খ ᭄ Ў GBK ᯊ ˈ Ⳍ ᔧ Ѣ 䇗 ⫼ HttpServletRequest ⱘ setCharacterEncodingᮍ⊩DŽ
y struts.objectFactory˖ᣛᅮ Struts 2 咬䅸ⱘ ObjectFactory Beanˈ䆹ሲᗻ咬䅸ؐᰃ springDŽ y struts.objectFactory.spring.autoWire˖ᣛᅮ Spring Ḛᶊⱘ㞾ࡼ㺙䜡ᓣˈ䆹ሲᗻⱘ咬
䅸ؐᰃ nameˈे咬䅸ḍ Bean ⱘ name ሲᗻ㞾ࡼ㺙䜡DŽ
y struts.objectFactory.spring.useClassCache˖䆹ሲᗻᣛᅮᭈড় Spring Ḛᶊᯊˈᰃ৺㓧ᄬ Beanᅲ՟ˈ䆹ሲᗻাܕ䆌Փ⫼ true false ϸϾሲᗻؐˈᅗⱘ咬䅸ؐᰃ trueDŽ䗮ᐌ ϡᓎ䆂ׂᬍ䆹ሲᗻؐDŽ
y struts.objectTypeDeterminer˖䆹ሲᗻᣛᅮ Struts 2 ⱘ㉏ൟẔ⌟ᴎࠊˈ䗮ᐌᬃᣕ tiger
notiger ϸϾሲᗻؐDŽ
y struts.multipart.parser˖䆹ሲᗻᣛᅮ໘⧚ multipart/form-data ⱘ MIME ㉏ൟ˄᭛ӊϞ Ӵ˅䇋∖ⱘḚᶊˈ䆹ሲᗻᬃᣕ cosǃpell jakarta ㄝሲᗻؐˈेߚ߿ᇍᑨՓ⫼ cos ⱘ᭛ӊϞӴḚᶊǃpell ϞӴঞ common-fileupload ᭛ӊϞӴḚᶊDŽ䆹ሲᗻⱘ咬䅸ؐЎ jakartaDŽ
3 ゴ Struts 2 ⸔
㰩ぐ བᵰ䳔㽕Փ⫼ cos 㗙 pell ⱘ᭛ӊϞӴᮍᓣˈ߭ᑨ䆹ᇚᇍᑨⱘ JAR ᭛ ӊࠊࠄ Web ᑨ⫼ЁDŽ՟བˈՓ⫼ cos ϞӴᮍᓣˈ߭䳔㽕㞾Ꮕϟ䕑 cos Ḛᶊ ⱘ JAR ᭛ӊˈᑊᇚ䆹᭛ӊᬒ WEB-INF/lib 䏃ᕘϟDŽ
y struts.multipart.saveDir˖䆹ሲᗻᣛᅮϞӴ᭛ӊⱘЈᯊֱᄬ䏃ᕘˈ䆹ሲᗻⱘ咬䅸ؐᰃ javax.servlet.context.tempdirDŽ
y struts.multipart.maxSize˖䆹ሲᗻᣛᅮ Struts 2 ᭛ӊϞӴЁᭈϾ䇋∖ݙᆍܕ䆌ⱘ᳔ᄫ 㡖᭄DŽ
y struts.custom.properties˖䆹ሲᗻᣛᅮ Struts 2 ᑨ⫼ࡴ䕑⫼᠋㞾ᅮНⱘሲᗻ᭛ӊˈ䆹㞾 ᅮНሲᗻ᭛ӊᣛᅮⱘሲᗻϡӮ㽚Ⲫ struts.properties ᭛ӊЁᣛᅮⱘሲᗻDŽབᵰ䳔㽕ࡴ
䕑Ͼ㞾ᅮНሲᗻ᭛ӊˈϾ㞾ᅮНሲᗻ᭛ӊⱘ᭛ӊৡҹ㣅᭛䗫ো˄,˅䱨ᓔDŽ y struts.mapper.class˖ᣛᅮᇚ HTTP 䇋∖ᇘࠄᣛᅮ Action ⱘᇘ఼ˈStruts 2 ᦤկњ
咬䅸ⱘᇘ఼˖org.apache.struts2.dispatcher.mapper.DefaultActionMapperDŽ咬䅸ᇘ
఼ḍ䇋∖ⱘࠡ㓔Ϣ Action ⱘ name ሲᗻᅠ៤ᇘDŽ
y struts.action.extension˖䆹ሲᗻᣛᅮ䳔㽕 Struts 2 ໘⧚ⱘ䇋∖ৢ㓔ˈ䆹ሲᗻⱘ咬䅸ؐ
ᰃ actionˈे᠔᳝ऍ䜡*.action ⱘ䇋∖䛑⬅ Struts 2 ໘⧚DŽབᵰ⫼᠋䳔㽕ᣛᅮϾ䇋
∖ৢ㓔ˈ߭Ͼৢ㓔П䯈ҹ㣅᭛䗫ো˄,˅䱨ᓔDŽ
y struts.serve.static˖䆹ሲᗻ䆒㕂ᰃ৺䗮䖛 JAR ᭛ӊᦤկ䴭ᗕݙᆍ᳡ࡵˈ䆹ሲᗻাᬃᣕ true false ሲᗻؐˈ䆹ሲᗻⱘ咬䅸ሲᗻؐᰃ trueDŽ
y struts.serve.static.browserCache˖䆹ሲᗻ䆒㕂⌣㾜఼ᰃ৺㓧ᄬ䴭ᗕݙᆍDŽᔧᑨ⫼໘Ѣ ᓔথ䰊↉ᯊˈ៥ӀᏠᳯ↣䇋∖䛑㦋ᕫ᳡ࡵ఼ⱘ᳔ᮄડᑨˈ߭ৃ䆒㕂䆹ሲᗻЎ falseDŽ y struts.enable.DynamicMethodInvocation˖䆹ሲᗻ䆒㕂 Struts 2 ᰃ৺ᬃᣕࡼᗕᮍ⊩䇗⫼ˈ
䆹ሲᗻⱘ咬䅸ؐᰃ trueDŽབᵰ䳔㽕݇䯁ࡼᗕᮍ⊩䇗⫼ˈ߭ৃ䆒㕂䆹ሲᗻЎ falseDŽ y struts.enable.SlashesInActionNames˖䆹ሲᗻ䆒㕂 Struts 2 ᰃ৺ܕ䆌 Action ৡЁՓ
⫼᭰㒓ˈ䆹ሲᗻⱘ咬䅸ؐᰃ falseDŽབᵰᓔথ㗙Ꮰᳯܕ䆌 Action ৡЁՓ⫼᭰㒓ˈ
߭ৃ䆒㕂䆹ሲᗻЎ trueDŽ
y struts.tag.altSyntax˖䆹ሲᗻᣛᅮᰃ৺ܕ䆌 Struts 2 ᷛㅒЁՓ⫼㸼䖒ᓣ䇁⊩ˈЎ䗮ᐌ 䛑䳔㽕ᷛㅒЁՓ⫼㸼䖒ᓣ䇁⊩ˈᬙℸሲᗻᑨ䆹䆒㕂Ў trueˈ䆹ሲᗻⱘ咬䅸ؐᰃ trueDŽ y struts.devMode˖䆹ሲᗻ䆒㕂 Struts 2 ᑨ⫼ᰃ৺Փ⫼ᓔথᓣDŽབᵰ䆒㕂䆹ሲᗻЎ trueˈ
߭ৃҹᑨ⫼ߎ䫭ᯊᰒ⼎ǃটདⱘߎ䫭ᦤ⼎DŽ䆹ሲᗻাফ true flase ϸ Ͼؐˈ䆹ሲᗻⱘ咬䅸ؐᰃ falseDŽ䗮ᐌˈᑨ⫼ᓔথ䰊↉ˈᇚ䆹ሲᗻ䆒㕂Ў trueˈᔧ 䖯ܹѻકথᏗ䰊↉ৢˈ߭䆹ሲᗻ䆒㕂Ў falseDŽ
y struts.i18n.reload˖䆹ሲᗻ䆒㕂ᰃ৺↣ HTTP 䇋∖ࠄ䖒ᯊˈ㋏㒳䛑䞡ᮄࡴ䕑䌘⑤᭛
ӊDŽ䆹ሲᗻ咬䅸ؐᰃ falseDŽᓔথ䰊↉ᇚ䆹ሲᗻ䆒㕂Ў true Ӯ᳝߽ѢᓔথˈԚ
ѻકথᏗ䰊↉ᑨᇚ䆹ሲᗻ䆒㕂Ў falseDŽ
㌑䡻 ᓔথ䰊↉ᇚ䆹ሲᗻ䆒㕂њ trueˈᇚৃҹ↣䇋∖ᯊ䛑䞡ᮄࡴ䕑䰙
࣪䌘⑤᭛ӊˈҢ㗠ৃҹ䅽ᓔথ㗙ⳟࠄᅲᯊᓔথᬜᵰ˗ѻકথᏗ䰊↉ᑨ䆹ᇚ䆹 ሲᗻ䆒㕂Ў falseˈᰃЎњᦤկડᑨᗻ㛑ˈ↣䇋∖䛑䳔㽕䞡ᮄࡴ䕑䌘⑤᭛ӊ Ӯ䰡Ԣᑨ⫼ⱘᗻ㛑DŽ
81
y struts.ui.theme˖䆹ሲᗻᣛᅮ㾚ᷛㅒ咬䅸ⱘ㾚Џ乬ˈ䆹ሲᗻⱘ咬䅸ؐᰃ xhtmlDŽ y struts.ui.templateDir˖䆹ሲᗻᣛᅮ㾚Џ乬᠔䳔㽕ᵓ᭛ӊⱘԡ㕂ˈ䆹ሲᗻⱘ咬䅸ؐ
ᰃ templateˈे咬䅸ࡴ䕑 template 䏃ᕘϟⱘᵓ᭛ӊDŽ
y struts.ui.templateSuffix˖䆹ሲᗻᣛᅮᵓ᭛ӊⱘৢ㓔ˈ䆹ሲᗻⱘ咬䅸ሲᗻؐᰃ ftlDŽ 䆹ሲᗻ䖬ܕ䆌Փ⫼ ftlǃvm jspˈߚ߿ᇍᑨ FreeMarkerǃVelocity JSP ᵓDŽ y struts.configuration.xml.reload˖䆹ሲᗻ䆒㕂ᔧ struts.xml ᭛ӊᬍবৢˈ㋏㒳ᰃ৺㞾ࡼ
䞡ᮄࡴ䕑䆹᭛ӊDŽ䆹ሲᗻⱘ咬䅸ؐᰃ falseDŽ
y struts.velocity.configfile˖䆹ሲᗻᣛᅮ Velocity Ḛᶊ᠔䳔ⱘ velocity.properties ᭛ӊⱘ ԡ㕂DŽ䆹ሲᗻⱘ咬䅸ؐЎ velocity.propertiesDŽ
y struts.velocity.contexts˖䆹ሲᗻᣛᅮ Velocity Ḛᶊⱘ Context ԡ㕂ˈབᵰ䆹Ḛᶊ᳝
Ͼ Contextˈ߭Ͼ Context П䯈ҹ㣅᭛䗫ো˄,˅䱨ᓔDŽ
y struts.velocity.toolboxlocation˖䆹ሲᗻᣛᅮ Velocity Ḛᶊⱘ toolbox ⱘԡ㕂DŽ
y struts.url.http.port˖䆹ሲᗻᣛᅮ Web ᑨ⫼᠔ⱘⲥッষDŽ䆹ሲᗻ䗮ᐌ≵᳝ⱘ
⫼᠋ˈাᰃᔧ Struts 2 䳔㽕⫳៤ URL ᯊ˄՟བ Url ᷛㅒ˅ˈ䆹ሲᗻᠡᦤկ Web ᑨ⫼
ⱘ咬䅸ッষDŽ
y struts.url.https.port˖䆹ሲᗻ㉏ԐѢ struts.url.http.port ሲᗻⱘ⫼ˈऎ߿ᰃ䆹ሲᗻᣛᅮ ⱘᰃ Web ᑨ⫼ⱘࡴᆚ᳡ࡵッষDŽ
y struts.url.includeParams˖䆹ሲᗻᣛᅮ Struts 2 ⫳៤ URL ᯊᰃ৺ࣙ䇋∖খ᭄DŽ䆹ሲ ᗻফ noneǃget all ϝϾሲᗻؐˈߚ߿ᇍᑨѢϡࣙǃҙࣙ GET ㉏ൟ䇋∖খ
᭄ܼࣙ䚼䇋∖খ᭄DŽ
y struts.custom.i18n.resources˖䆹ሲᗻᣛᅮ Struts 2 ᑨ⫼᠔䳔㽕ⱘ䰙࣪䌘⑤᭛ӊˈབ ᵰ᳝ӑ䰙࣪䌘⑤᭛ӊˈ߭Ͼ䌘⑤᭛ӊⱘ᭛ӊৡҹ㣅᭛䗫ো˄,˅䱨ᓔDŽ
y struts.dispatcher.parametersWorkaround˖ᇍѢᶤѯ Java EE ᳡ࡵ఼ˈϡᬃᣕ HttpServlet Request䇗⫼ getParameterMap()ᮍ⊩ˈℸᯊৃҹ䆒㕂䆹ሲᗻؐЎ true ᴹ㾷އ䆹䯂乬DŽ 䆹ሲᗻⱘ咬䅸ؐᰃ falseDŽᇍѢ WebLogicǃOrion OC4J ᳡ࡵ఼ˈ䗮ᐌᑨ䆹䆒㕂䆹 ሲᗻЎ trueDŽ
y struts.freemarker.manager.classname˖䆹ሲᗻᣛᅮ Struts 2 Փ⫼ⱘ FreeMarker ㅵ⧚఼DŽ 䆹 ሲ ᗻ ⱘ 咬 䅸 ؐ ᰃ org.apache.struts2.views.freemarker.FreemarkerManager ˈ 䖭 ᰃ Struts 2ݙᓎⱘ FreeMarker ㅵ⧚఼DŽ
y struts.freemarker.wrapper.altMap˖䆹ሲᗻাᬃᣕ true false ϸϾሲᗻؐˈ咬䅸ؐᰃ trueDŽ䗮ᐌ᮴䳔ׂᬍ䆹ሲᗻؐDŽ
y struts.xslt.nocache˖䆹ሲᗻᣛᅮ XSLT Result ᰃ৺Փ⫼ḋᓣ㸼㓧ᄬDŽᔧᑨ⫼໘Ѣᓔথ 䰊↉ᯊˈ䆹ሲᗻ䗮ᐌ㹿䆒㕂Ў true˗ᔧᑨ⫼໘ѢѻકՓ⫼䰊↉ᯊˈ䆹ሲᗻ䗮ᐌ㹿䆒 㕂Ў falseDŽ
y struts.configuration.files˖䆹ሲᗻᣛᅮ Struts 2 Ḛᶊ咬䅸ࡴ䕑ⱘ䜡㕂᭛ӊˈབᵰ䳔㽕ᣛ ᅮ咬䅸ࡴ䕑Ͼ䜡㕂᭛ӊˈ߭Ͼ䜡㕂᭛ӊⱘ᭛ӊৡП䯈ҹ㣅᭛䗫ো˄,˅䱨ᓔDŽ䆹 ሲᗻⱘ咬䅸ؐЎ struts-default.xml,struts-plugin.xml,struts.xmlˈⳟࠄ䆹ሲᗻؐˈ䇏㗙 ᑨ䆹ᯢⱑЎҔМ Struts 2 Ḛᶊ咬䅸ࡴ䕑 struts.xml ᭛ӊњDŽ
3 ゴ Struts 2 ⸔
᳝ѯᯊˈᓔথ㗙ϡ୰Փ⫼乱ⱘ struts.properties ᭛ӊˈStruts 2 ܕ䆌 struts.xml
᭛ӊЁㅵ⧚ Struts 2 ሲᗻˈ struts.xml ᭛ӊЁ䗮䖛䜡㕂 constant ܗ㋴ˈϔḋৃҹ䜡㕂䖭ѯ ሲᗻDŽ
struts.xml䜡㕂⠛↉བϟ˖
<?xml version="1.0" encoding="UTF-8" ?>
<!-- ᣛᅮ Struts 2 ⱘ DTD ֵᙃ -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- 䗮䖛 constant ܗ㋴䜡㕂 Struts 2 ⱘሲᗻ -->
<constant name=" struts.custom.i18n.resources " value="mess" />
...
</struts>
Ϟ䴶ҷⷕ⠛↉䜡㕂њϔϾᐌ⫼ሲᗻ˖struts.custom.i18n.resourcesˈ䆹ሲᗻᣛᅮњᑨ⫼᠔ 䳔ⱘ䰙࣪䌘⑤᭛ӊⱘ baseName Ў messDŽ
㌑䡻 Struts 2 ᦤկњϸ⾡ᮍᓣᴹㅵ⧚ Struts 2 ⱘሲᗻ˖᮶ৃҹ䗮䖛 struts.properties᭛ӊᴹ䜡㕂 Struts 2 ሲᗻˈгৃ䗮䖛 struts.xml ᭛ӊЁ䜡㕂 constantܗ㋴ᴹ䜡㕂 Struts 2 ሲᗻDŽ