Apache Struts 2 namespace Combat Chszs, copyright, without consent, may not be reproduced. Blogger Home: Http://blog.csdn.net/chszs
The Apache Struts 2 namespace is a new concept that enables multi-module processing by assigning a single namespace to each module. In addition, it solves the problem of name conflict of the same acion name under different modules.
From the figure below we can understand how the URL matches the Struts 2 namespace.
One, the configuration of the namespace
Below we illustrate how it matches URLs and directories by using the Struts2 namespace configuration instance. To illustrate a point, the package name (that is, the "default") does not affect the URL match result, it is just a meaningful name.
Struts.xml
<?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="default" namespace="/" extends="struts-default"> <action name="SayWelcome"> <result>pages/welcome.jsp</result> </action> </package> <package name="common" namespace="/common" extends="struts-default"> <action name="SayWelcome"> <result>pages/welcome.jsp</result> </action> </package> <package name="user" namespace="/user" extends="struts-default"> <action name="SayWelcome"> <result>pages/welcome.jsp</result> </action> </package></struts>
The diagram for the action namespace of Struts 2 maps to the directory is as follows:
Second, JSP page
I put three JSP files of the same file name, but they are in different modules.
1) Root-webapp/pages/welcome.jsp
2) Common module--webapp/common/pages/welcome.jsp
3) User Module--webapp/user/pages/welcome.jsp
Iii. mechanism of work
To run the project, we can access different namespaces by accessing different URLs separately.
Example 1
Url:http://localhost:8080/struts2example/saywelcome.action
This will match the root namespace.
<package name="default" namespace="/" extends="struts-default"> <action name="SayWelcome"> <result>pages/welcome.jsp</result> </action></package>
The contents of the webapp/pages/welcome.jsp are displayed.
Example 2
Url:http://localhost:8080/struts2example/common/saywelcome.action
This will match the common namespace.
<package name="common" namespace="/common" extends="struts-default"> <action name="SayWelcome"> <result>pages/welcome.jsp</result> </action></package>
The contents of the webapp/common/pages/welcome.jsp are displayed.
Example 3
Url:http://localhost:8080/struts2example/user/saywelcome.action
This will match the user namespace.
<package name="user" namespace="/user" extends="struts-default"> <action name="SayWelcome"> <result>pages/welcome.jsp</result> </action></package>
The contents of the webapp/user/pages/welcome.jsp are displayed.
Copyright NOTICE: This article for Bo Master Chszs original article, without Bo Master permission not reproduced.
Apache Struts 2 's namespace combat