Use of namespaces in Struts2

Source: Internet
Author: User

In the Web, if you need multiple action with the same name, you can manage the action by using namespaces. See the following examples in detail:

Project name: Strutsdemo, in the configuration Struts.xml, mainly in package to join namespace= "* * *", see Example 2.

1, 1<?xml version= "1.0" encoding= "GBK"?>
2 2<! DOCTYPE Struts Public
3 3 "-//apache Software foundation//dtd Struts Configuration 2.0//en"
4 4 "HTTP://STRUTS.APACHE.ORG/DTDS/STRUTS-2.0.DTD" >
5 5<struts>
6 6
7 7 <package name= "org" extends= "Struts-default" >
<action name= "Login" class= org. Loginaction ">
<result name= "Input" >/login.jsp</result>
1010 <result name= "Error" >/error.jsp</result>
1111 <result name= "Success" >/welcome.jsp</result>
1212 </action>
1313 <action name= "getusers" class= org. Getusersaction ">
1414 <result name= "Login" >/login.jsp</result>
1515 <result name= "Success" >/listUsers.jsp</result>
1616 </action>
1717 </package>
1818</struts>

can be accessed through http://localhost:8080/strutsdemo/getUsers.action

 2, 1<?xml version= "1.0" encoding= "GBK" 
2<! DOCTYPE struts Public
3 "-//apache Software foundation//dtd struts Configuration 2.0//en"
4 "Http://struts.apa CHE.ORG/DTDS/STRUTS-2.0.DTD
5<struts>
6
7
8
9 <package name= "org" extends= Struts-default "
<action name=" login "class=" org. Loginaction ""
One <result name= "input" >/LOGIN.JSP</RESULT>
<result name= "error" >/er Ror.jsp</result>
<result name= "Success" >/welcome.jsp</result>
</ACTION>
15 </package>

<package name= "Get" extends= "Struts-default" namespace= "/apple"
<ac tion name= "getusers" class= org. Getusersaction "
<result name=" Login ">/login.jsp</result>
<result name=" Success "&G T;/listuser.jsp</result>
</action>
</package>
23</struts> can pass http:// Locahost:8080/strutsdemo/apple/getusers.action access to

Example 1 is a property that does not specify a namespace, the default namespace is empty, and Example 2 has namespace Apple.

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.