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