Struts2 package and namespace, struts2 namespace

Source: Internet
Author: User

Struts2 package and namespace, struts2 namespace

Struts2 provides the namespace function to handle the case where the same WEB application contains an Action with the same name. Struts2 manages actions in a namespace. actions with the same name cannot exist in the same namespace, and actions with the same name can exist in different namespaces.

Struts2 does not support setting namespaces for individual actions. Instead, it uses the namespace attribute to specify a common namespace for all actions under the package. If the namespace attribute is not specified when <package.../> is configured, all actions under the package are in the default package space.


<? 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>
<! -- Configure the get package. The package inherits the default package of Struts2 and specifies the package namespace as/book --!>
<Package name = "get" namespace = "/book" extends = "struts-default">
<Action name = "getBooks" class = "cn. ss. GetBookAction" method = "execute">
<Result name = "success">/WEB-INF/JspPage/chapter1/HelloWorld. jsp </result>
</Action>
</Package>
</Struts>

After a package has a namespace specified, all the actions under the package should be processed by the namespace + Action name. The preceding example shows that the package contains the Action named getBooks, the URL processed by this Action is:
Http: /localhost: 8080/namespace/book/getBooks. action
// 8080 is the server port, namespace is the application name, book is The namespace corresponding to the Action package, and getBooks is the Action name

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.