Struts2 configuration file modular inclusion (include) and action Summary

Source: Internet
Author: User

This function is better when there are many Struts configuration files that need to be divided or separated into multiple configuration files.

Use the <include> label to introduce other configuration files to the Struts. xml configuration file.

For example, a login. xml configuration file is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE struts PUBLIC
"-// Apache Software Foundation // DTD Struts Configuration 2.0 // EN"
Http://struts.apache.org/dtds/struts-2.0.dtd>
<Struts>
<Package name = "login" extends = "struts-default" namespace = "/login">
<Action name = "login *" class = "com. bjsxt. struts2.user. action. LoginAction {1}">
<Result>/user_login_success.jsp </result>
</Action>
</Package>
</Struts>

<? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE struts PUBLIC
"-// Apache Software Foundation // DTD Struts Configuration 2.0 // EN"
Http://struts.apache.org/dtds/struts-2.0.dtd>
<Struts>
<Package name = "login" extends = "struts-default" namespace = "/login">
<Action name = "login *" class = "com. bjsxt. struts2.user. action. LoginAction {1}">
<Result>/user_login_success.jsp </result>
</Action>
</Package>
</Struts>
[Html] view plaincopyprint?


You need to use the <include> label in the struts. xml file to introduce it. Struts. xml is as follows


[Java] <? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE struts PUBLIC
"-// Apache Software Foundation // DTD Struts Configuration 2.0 // EN"
Http://struts.apache.org/dtds/struts-2.0.dtd>
 
<Struts>
<Constant name = "struts. devMode" value = "true"/>
<Include file = "login. xml"/>
</Struts>

<? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE struts PUBLIC
"-// Apache Software Foundation // DTD Struts Configuration 2.0 // EN"
Http://struts.apache.org/dtds/struts-2.0.dtd>

<Struts>
<Constant name = "struts. devMode" value = "true"/>
<Include file = "login. xml"/>
</Struts>

 

1. Default Action

The default Action is used when the user accesses the namespace for the next Action that does not exist.

Use the <default-action-ref name = "name"> label. The name attribute points to the Action name defined below.

[Html] <struts>
<Constant name = "struts. devMode" value = "true"/>

<Package name = "default" namespace = "/" extends = "struts-default">
<Default-action-ref name = "index"> </default-action-ref>
<Action name = "index">
<Result>/default. jsp </result>
</Action>
</Package>
</Struts>

<Struts>
<Constant name = "struts. devMode" value = "true"/>

<Package name = "default" namespace = "/" extends = "struts-default">
<Default-action-ref name = "index"> </default-action-ref>
<Action name = "index">
<Result>/default. jsp </result>
</Action>
</Package>
</Struts>


When no Action exists under the current access namespace = "/", the system returns the automatically forwarded to the access/default. jsp page.

 

I. Action Summary

1. The most common way to implement an Action: Inherit from ActionSupport

2. DMI dynamic call :!

3. wildcard configuration: * {1} {2}

4. Method of receiving parameters (generally, properties or DomainModel are used to receive parameters)

5. Simple parameter verification addFieldError

A) generally, the Struts UI tag is not used.

6. Access Web elements

A) Map type

I. IoC

Ii. Dependency on Struts2

B) Original Type

I. IoC

Ii. Dependency on Struts2

7. Include File Configuration


 

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.