Struts2 constant Introduction

Source: Internet
Author: User
Tags i18n xslt

After several introductions, I 'd like to have a preliminary understanding of struts2, let me talk about the usage and use of constants in struts2 (constant default configuration struts2-core-2.x.x.x/org/Apache/struts2/default. properties file ).

I.Constant Configuration:

To use constants, you must first implement them through configuration. constants can be defined in multiple files below. The search sequence of constants carried by struts2 is as follows. Subsequent settings can overwrite the previous settings:
Default. properties file struts2-core-*. jar --> org. Apache. struts2
Struts-default.xml struts2-core-*. Jar
Struts-plugin.xml struts2-spring-plugin-*. Jar/struts2-convention-plugin-*. Jar!
Struts. xml
Struts. Properties
Web. xml


1. Use the Struts. propreties file configuration to maintain backward compatibility with webwork.

2. In actual development, configuring constants in Web. XML requires more code than the other two types, which reduces the readability of Web. xml.

3. We recommend that you configure struts2 constants in the Struts. xml file for centralized management.

Ii. constants:

Specify default encoding
Usage: <constant name = "struts. i18n. encoding" value = "UTF-8"/>
Specifies the request suffix processed by struts 2. The default value is action, that is, all matches *. all action requests are processed by struts2. If you need to specify multiple request suffixes, multiple suffixes are separated by commas (,).
Usage: <constant name = "struts. Action. Extension" value = "do"/> or
     <constant name="struts.action.extension" value="do,action" />
After the struts configuration file is modified, whether the system automatically reloads the file. The default value is false (used in the production environment ).
Usage: <constant name = "struts. configuration. xml. Reload" value = "true"/>
Used in development mode. The default value is false and the value is set to true. In this way, more detailed error information can be printed to help you find the error. It is recommended to enable it during development. After the project is released, change it to false.
<constant name="struts.devMode" value="true" />
This attribute specifies the mime-type multipart/form-data processing method. There are three upload Methods: cos, Pell, and Jakarta. struts2 adopts the third method by default, if you want to use the first two methods, you need to download the corresponding jar package online.
Usage: <constant name = "struts. multipart. parser" value = "Cos"/>
         <constant name="struts.multipart.parser" value="pell" />  
         <constant name="struts.multipart.parser" value="jakarta" />
Specifies the temporary directory when the file is uploaded. By default, javax. servlet. Context. tempdir is used.
Usage: <constant name = "struts. multipart. savedir" value = "/tmpuploadfiles"/>
This attribute specifies the maximum number of bytes allowed for the entire request content during struts 2 File Upload. The default value is 2 MB.
Usage: <constant name = "struts. multipart. maxsize" value = "2097152"/>
Default view topic, which can be simple, XHTML, or Ajax
Usage: <constant name = "struts. UI. Theme" value = "simple"/>
Sets whether the browser caches static content. The default value is true (used in the production environment). It is best to disable it during development.
Usage: <constant name = "struts. Serve. Static. browsercache" value = "false"/>
Set whether a diagonal line can be used in an action. The default value is false. The default value is true.
Usage: <constant name = "struts. Enable. slashesinactionnames" value = "true"/>
Set whether to support dynamic method calls. True is supported, and false is not supported.
Usage: <constant name = "struts. Enable. dynamicmethodinvocation" value = "true"/>
The following are some of the less common constant usage methods. You need to know: because the focus is on struts2, the constants used for integration with spring will also be explained in spring, I will not talk about it here.
<! -- Specify the request URL and action er. The default value is Org. apache. struts2.dispatcher. mapper. defaultactionmapper --> <constant name = "struts. mapper. class "value =" org. apache. struts2.dispatcher. mapper. defaultactionmapper "/> <! -- Whether expression syntax is allowed. The default value is true. --> <constant name = "struts. Tag. altsyntax" value = "true"/> <! -- Template directory --> <cosntant name = "struts. UI. templatedir" value = "template"/> <! -- Set the template type. It can be FTL, Vm, or JSP --> <cosntant name = "struts. UI. templatesuffix" value = "FTL"/> <! -- Locate the velocity. properties file. Default Value: velocity. properties --> <cosntant name = "struts. Velocity. configfile" value = "velocity. properties"/> <! -- Set context. --> <cosntant name = "struts. Velocity. contexts" value = "..."/> <! -- Locate toolbox --> <cosntant name = "struts. Velocity. toolboxlocation" value = "..."/> <! -- Specify the web application port --> <cosntant name = "struts. url. http. Port" value = "80"/> <! -- This attribute specifies that the struts2 application loads the custom property file. The property specified in this custom property file does not overwrite the property specified in the Struts. properties file. To load multiple custom attribute files, separate the names of multiple custom attribute files with commas. (That is, do not rewrite struts. properties !) --> <Constant name = "struts. Custom. properties" value = "application, org/Apache/struts2/extension/custom"/> <! -- Specify the encrypted port --> <cosntant name = "struts. url. HTTPS. Port" value = "443"/> <! -- Set whether to include parameters when generating a URL. the value can be none, get or all --> <cosntant name = "struts. URL. includeparams "value =" get "/> <! -- Set the international resource files to be loaded, separated by commas (,). --> <cosntant name = "struts. Custom. i18n. Resources" value = "application"/> <! -- Some web application servers cannot process httpservletrequest. getparametermap (), such as WebLogic, Orion, and Solaris, must be set to true. The default value is false. --> <cosntant name = "struts. dispatcher. parametersworkaround "value =" false "/> <! -- Specify freemarker manager --> <cosntant name = "struts. freemarker. Manager. classname" value = "org. Apache. struts2.views. freemarker. freemarkermanager"/> <! -- Set whether to set cache for the freemarker template. The effect is equivalent to copying the template to web_app/templates. --> <cosntant name = "struts. freemarker. templatescache "value =" false "/> <! -- You do not need to modify this attribute. --> <cosntant name = "struts. freemarker. wrapper. altmap" value = "true"/> <! -- Specify whether the XSLT result is cached in the style sheet. set the development phase to true and the release phase to false. --> <cosntant name = "struts. XSLT. nocache "value =" false "/> <! -- Set the list of files automatically loaded by struts. --> <cosntant name = "struts. configuration. Files" value = "struts-default.xml, struts-plugin.xml, Struts. xml"/> <! -- Set whether to always select namespace anywhere before the last slash. --> <cosntant name = "struts. Mapper. alwaysselectfullnamespace" value = "false"/> <! -- Required for spring hosting and spring Integration --> <constant name = "struts. objectfactory" value = "Spring"/> <! -- Specify to load the struts2 Configuration File Manager. The default value is org. Apache. struts2.config. defaultconfiguration. You can customize the configuration file manager. To implement the configuration interface, you can automatically load the struts2 configuration file. --> <Constant name = "struts. Configuration" value = "org. Apache. struts2.config. defaultconfiguration"/> <! -- Set the default locale and character encoding for international use --> <constant name = "struts. locale "value =" zh_cn "/> <constant name =" struts. i18n. encoding "value =" UTF-8 "/> <! -- Specify the struts factory class --> <constant name = "struts. objectfactory" value = "Spring"> </constant> <! -- Specify the Assembly mode of the Spring framework. The assembly methods include name, type, auto, and constructor (name is the default Assembly mode) --> <constant name = "struts. objectfactory. spring. autowire "value =" name "/> <! -- This attribute specifies whether to cache bean when spring is integrated. The value is true or false. The default value is true --> <cosntant name = "struts. objectfactory. spring. useclasscache "/> <! -- Specify the type check, including tiger and notiger --> <cosntant name = "struts. objecttypedeterminer" value = "tiger"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.