<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<p>Struts 2 Namespace is a new concept to handle the multiple modules by given a namespace to each module. In addition, it can used to avoid conflicts between same action names located at different modules.</p>
<p>See this picture to understand how a URL match to Struts 2 action namespace.</p>
<p> ;</p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/07/namespace.png" border="0" /></div>
</div>
<h2><b>1. Namespace configuration-</b></h2>
<p>Let go through a Struts 2 namescape configuration example to know how it match with URL and folder.<br />
The package &#8220;login&#8221; will not affect the result, just give a meaningful name.<br />
<b>struts.xml</b></p>
<pre class="highlight"><;?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.enable.DynamicMethodInvocation" value="false" />; 
 <;constant name="struts.devMode" value="false" />; 
 <;constant name="struts.custom.i18n.resources" value="myapp" />; 
 
 <;package name="default" extends="struts-default" namespace="/">; 
 <;action name="welcome" class="com.dineshonjava.struts2.login.LoginAction">; 
 <;result name="success">;/Welcome.jsp<;/result>; 
 <;result name="error">;/Login.jsp<;/result>; 
 <;/action>; 
 <;/package>; 
 
 <;package name="login" extends="struts-default" namespace="/login">; 
 <;action name="welcome" class="com.dineshonjava.struts2.login.LoginAction">; 
 <;result name="success">;/Welcome.jsp<;/result>; 
 <;result name="error">;/Login.jsp<;/result>; 
 <;/action>; 
 <;/package>; 
 
 <;package name="welocome" extends="struts-default" namespace="/welcome">; 
 <;action name="welcome" class="com.dineshonjava.struts2.login.LoginAction">; 
 <;result name="success">;/Welcome.jsp<;/result>; 
 <;result name="error">;/Login.jsp<;/result>; 
 <;/action>; 
 <;/package>; 
<;/struts>; 
</pre>
<div id="ads-id" align="center"></div>
</div>
<h2><b>2. JSP View Pages</b></h2>
<p>3 JSP view pages with same file name but locate at different modules.<br />
<b>1. View Root namespace</b></p>
<pre class="highlight"><;%@ page contentType="text/html; charset=UTF-8"%>; 
<;%@ taglib prefix="s" uri="/struts-tags"%>; 
<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">; 
<;html>; 
<;head>; 
<;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">; 
<;title>;Welcome<;/title>; 
<;/head>; 
 
<;body>; 
 <;h2>;Default namespace<;/h2>; 
 <;h2>;Hello Welcome , <;s:property value="username" />;...! Dineshonjava.com<;/h2>; 
 
<;/body>; 
<;/html>; 
</pre>
</div>
<p><b>URL : <i>http://localhost:8080/doj/welcome.action</i></b><br />
<b>Will match the root namespace.</b></p>
<pre class="highlight"><;package name="default" extends="struts-default" namespace="/">; 
 <;action name="welcome" class="com.dineshonjava.struts2.login.LoginAction">; 
 <;result name="success">;/Welcome.jsp<;/result>; 
 <;result name="error">;/Login.jsp<;/result>; 
 <;/action>; 
 <;/package>; 
</pre>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/07/11.png" border="0" /></div>
<p><b>2. View login namespace</b></p>
<pre class="highlight"><;%@ page contentType="text/html; charset=UTF-8"%>; 
<;%@ taglib prefix="s" uri="/struts-tags"%>; 
<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">; 
<;html>; 
<;head>; 
<;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">; 
<;title>;Welcome<;/title>; 
<;/head>; 
 
<;body>; 
 <;h2>;login namespace<;/h2>; 
 <;h2>;Hello Welcome , <;s:property value="username" />;...! Dineshonjava.com<;/h2>; 
 
<;/body>; 
<;/html>; 
</pre>
<p><b>URL : <i>http://localhost:8080/doj/login/welcome.action</i></b><br />
<b>Will match the login namespace.</b></p>
<pre class="highlight"><;package name="login" extends="struts-default" namespace="/login">; 
 <;action name="login" class="com.dineshonjava.struts2.login.LoginAction">; 
 <;result name="success">;/Welcome.jsp<;/result>; 
 <;result name="error">;/Login.jsp<;/result>; 
 <;/action>; 
 <;/package>; 
</pre>
</div>
<p> ;</p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/07/22.png" border="0" /></div>
<p><b>3. View welcome namespace-</b></p>
<pre class="highlight"><;%@ page contentType="text/html; charset=UTF-8"%>; 
<;%@ taglib prefix="s" uri="/struts-tags"%>; 
<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">; 
<;html>; 
<;head>; 
<;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">; 
<;title>;Welcome<;/title>; 
<;/head>; 
 
<;body>; 
 <;h2>;welcome namespace<;/h2>; 
 <;h2>;Hello Welcome , <;s:property value="username" />;...! Dineshonjava.com<;/h2>; 
 
<;/body>; 
<;/html>; 
</pre>
<p><b>URL : <i>http://localhost:8080/doj/welcome/welcome.action</i></b><br />
<b>Will match the welcome namespace.</b></p>
<pre class="highlight"><;package name="login" extends="struts-default" namespace="/welcome">; 
 <;action name="welcome" class="com.dineshonjava.struts2.login.LoginAction">; 
 <;result name="success">;/Welcome.jsp<;/result>; 
 <;result name="error">;/Login.jsp<;/result>; 
 <;/action>; 
 <;/package>; 
</pre>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/07/33.png" border="0" /></div>
<p> ;</p>
<h1>Reference</h1>
<ol>
<li><a style="text-decoration: underline;" href="http://struts.apache.org/2.0.14/docs/namespace-configuration.html" target="_blank" rel="noopener">Struts 2 Namespace Configuration Reference</a></li>
</ol>
<p> ;</p>
</div>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/struts-2-configuration-file/">Previous</a> <;<; || <a href="https://dineshonjava.com/struts-2-baby-step-to-learn/">Index </a>|| >;>;<a href="https://dineshonjava.com/a-tag-and-business-service/">Next</a> >;>;</b></div>
<p> ;</p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/struts-2-configuration-file/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/a-tag-and-business-service/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '392'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…