Framework learning struts2-02 Other configurations, exception frameworks, and internationalization

Source: Internet
Author: User
more about the STRUTS2 configuration XML Configuration
To configure the default namespace
1. When the corresponding namespace packet processing request is not found in the custom configuration file, the default namespace is matched
<package name= "Default" extends= "Struts-default" >
        <!--defaults to the processor reference: The Struts framework is informed that if the request is in this package but no corresponding processor is found, The default processor is used for processing-->
        <default-action-ref name= "notfoundaction"/> <action "name="
        class= "Sample.s2.web.action.NotFoundAction" >
            <result>/WEB-INF/jsp/404.jsp</result>
        < /action>
    </package>
Configure the Default processor class (configuration of custom processor classes not shown)
1. You can configure the default target processor class yourself
2. Also can write nothing, then the load will default to the above processor class to complete the processing of the request
<default-class-ref class= "xxx.xxx.xx ... Actionsupppot "/>
Configure global result processing results (for exception handling framework)
When an exception occurs, it is processed according to the global result.
    <global-results>
        <result name= "ex" >/WEB-INF/jsp/500.jsp</result>
    </global-results >
    <global-exception-mappings>
        <exception-mapping result= "ex" exception= "Java.lang.Exception" />
    </global-exception-mappings>
on the exception framework for STRUTS2 application of exception handling framework
The first is that you have the appropriate configuration information in the XML file and then you can output the corresponding exception error message or custom error page on the page:
${exception} expression can display exception information, if you want to display the details, we can use the Exception.stacktrace expression to traverse the output of exception information about the internationalization of struts2 Internationalization Configuration
Configure the following information in the total file to represent the read configuration information for the internationalized resource bundle
<constant name= "struts.custom.i18n.resources" value= "res"/>
preparing internationalized Resource Files
Under the SRC and the path. Create an internationalized resource properties file (res_zh_cn.properties, res_en_us.properties file) in the page output way, using the struts2 label output tag, in the attribute Name= "" Put in the key name (the key in the resource bundle) in the page to manually switch the implementation of international resources, directly in the switch country region of the hyperlink to add GET request parameters: .... REQUEST_LOCALE=RES_ZH_CN or Res_en_us (this is a fixed format) can be passed to an internationalized resource bundle by using a label when a parameter pass is encountered
<s:text name= "key Name" >
    <s:param> Pass parameters (can be completed with El Expression) </s:param>
 </s:text>

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: info-contact@alibabacloud.com 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.