Struts 2 Result Path Configuration with Examples

Filed Under: Struts 2

This is the third post in the Struts 2 series. You might want to check out earlier posts too.

  1. Struts Beginners Tutorial and Hello World XML Example
  2. Struts 2 Example with Annotation

In both the earlier posts, we used JSP pages as the result of action, in this post we will see some important points to note with the result location with example.

<package name="user" namespace="/User" extends="struts-default">
	<action name="home">

Above is the snippet from struts.xml file, notice that result element doesn’t start with a forward slash (/). In this case, struts will look for result JSP page at {WEBAPP-ROOT}/{Namespace}/{result} path. So our JSP file should be present at WEBAPP/User/results/ directory.

But if result element starts with forward slash, then struts look for file in the root folder. So if struts.xml file package element is:

<package name="user" namespace="/User" extends="struts-default">
	<action name="home">

Then struts will look for result page at WEBAPP/results/ directory.

Now take a look at below package declaration.

<package name="user" namespace="/User/" extends="struts-default">
	<action name="home">

Since the namespace is ending with “/” struts will look for result at WEBAPP/User/login.jsp even though result element starts with forward slash.

Let’s see how we can configure the result path if we are using annotation based configuration.

public class TestAction extends ActionSupport {


In above case, struts will try to locate file at WEB-INF/content/Test/results/login.jsp.

Usually we don’t put JSP or HTML files inside WEB-INF directory, so we can provide @Result location attribute value starting with forward slash to let struts look for files in the project root directory.

If we change above @Result annotation to @Result(location="/results/login.jsp"), then struts will look for file at WEBAPP/results/login.jsp

We can also use @ResultPath annotation to provide the result pages path.

public class TestAction extends ActionSupport {


Struts will look for login.jsp at WEBAPP/jsps/Test/ directory.

If you want to change result path from WEB-INF/content directory to some other directory globally, you can do it through struts configuration file.

<?xml version="1.0" encoding="UTF-8"?>

	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
<constant name="struts.convention.result.path" value="/"></constant>

That’s all for configuring the result pages location in struts 2, we will look into more of struts 2 features in future posts.


  1. Alok says:

    Dear Pankaj,

    I tried below thing its not working.
    Can you please explain me why it is?

    Package declaration



    Also I kept the result files in User directory (WebApp/User/login.jsp ; WebApp/User/welcome.jsp ; WebApp/User/error.jsp).

    I am getting below error on browser.
    HTTP Status 404 – There is no Action mapped for action name home.

    1. Alok says:

      Package declare – /User/ ends with forward slash, and result pages with forward slash too.

  2. ved prakash says:


    if we do not start with / in namespace it’s search from root . would u like to explain?

    1. Pankaj says:

      If you would not start “namespace” with “/” then u will get error like “There is no Action mapped for action name”.

      <package name=”user” namespace=”User” extends=”struts-default”>
      <action name=”home”>

      If you will try to access localhost:8080/Struts2XMLHelloWorld/User/home.action then you will get error result as:

      Struts Problem Report

      Struts has detected an unhandled exception:

      There is no Action mapped for action name home.

Comments are closed.

Generic selectors
Exact matches only
Search in title
Search in content