1

I am unable to execute my struts2 application. I am using eclipse indigo IDE, tomcat 7 and jdk 1.7.

The jar files I included are:

  • commons-logging-1.0.4.jar,
  • freemarker-2.3.8.jar,
  • ognl- 2.6.11.jar,
  • struts2-core-2.0.11.jar,
  • xwork-2.0.4.jar

I placed the struts.xml in classes folder in WEB-INF and I also tried it placing in
src folder but I could not able to make it. I am getting the below error on console

There is no Action mapped for namespace / and action name tutorial. - [unknown    location]

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>  
</head>  
<body>  
    <form action="./tutorial.action">  
        Username: <input type="text" />  
        <input type="submit" value="Submit" />  
    </form>  
</body>  
</html>  

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" extends="struts-default">
        <action name="tutorial" class="com.test.TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/failure.jsp</result>
        </action>
    </package>
</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
xmlns="http://java.sun.com/xml/ns/javaee"   
xmlns:web="http://java.sun.com/xml/ns/javaee/web-
app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

    <display-name>Struts2Starter</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

TutorialAction.java

package com.test;   

public class TutorialAction {   
    public String execute() {
        System.out.println("Hello from execute");   
        return "success";   
    }
}
Roman C
  • 49,761
  • 33
  • 66
  • 176
user1066912
  • 11
  • 1
  • 3
  • 2
    What code have you written so far? Have you created those actions? – cowls Dec 20 '12 at 18:46
  • Where's getTutorial coming from? I see "tutorial.action" in your form. Also shouldn't TutorialAction derive from ActionSupport? – TJ- Dec 20 '12 at 20:06
  • Actually even if if we don't extend ActionSupport also struts 2 app should work right . – user1066912 Dec 20 '12 at 20:16
  • I see. You may want to download a sample application and check if there's something that you are missing. http://struts.apache.org/download.cgi#struts231-SNAPSHOT – TJ- Dec 20 '12 at 20:27
  • So you are calling action which is not in your configuration. – Aleksandr M Dec 20 '12 at 20:45
  • make some mistake in above configuration file, when the server is getting started it reads the struts.xml configuration file. If there any problem it will worry about that and this confirms that you did right configuration. In struts2 struts2.xml should be in src folder. – MohanaRao SV Dec 20 '12 at 23:56

5 Answers5

3

As others have pointed out, you do not have a getTutorial action in your mapping, only a "tutorial". However, I'm going to skip over that and suggest that you learn how to sanity check a Struts2 app. Anytime you are setting up a new technology, and even when you are working with a familiar technology, it is very useful to understand how to do a basic sanity check -- in this case, you need to verify that your struts xml has been successfully parsed and the framework knows about your actions.

I HIGHLY RECOMMEND you add the Struts 2 Config Browser plugin to your struts 2 apps. To add the plugin, you just get the jar ( all struts 2 plugins are jars ) and put in your webapp's lib directory. That's it. When you start your applicaiton, hit this URL:

http://localhost:8080/starter/config-browser/index.action

And it shows you all of the actions, as well as other configurations, that the framework knows about. Essentialy struts 2 diagnostic tool, and too easy to use to not use it.

chad
  • 7,369
  • 6
  • 37
  • 56
0

Try to add namespace attribute into you package element of struts.xml file.

Like this:

<struts>
<package name="default" extends="struts-default" namespace="/">
    <action name="tutorial" class="com.test.TutorialAction">
        <result name="success">/success.jsp</result>
        <result name="failure">/failure.jsp</result>
    </action>
</package>
</struts>
Igorry
  • 177
  • 3
0

I had the same problem and I saw multiple posts on this one....here is the possible solution

I was pretty sure that I had mapped all my actions accurately, but it was showing the same error above....so I just cleaned the project and then ran it again..it worked perfectly fine...give it a try !

I encountered this so many times...so to avoid such kind of things, I just added "../eclipse.exe -clean" to the shortcut icon property....this works and u can forget about getting such kind of errors which is actually not an error....!

uLYsseus
  • 995
  • 6
  • 16
  • 37
0

Try this once don't append .action

<form action="tutorial">

place your struts.xml file in src outside the package or in WEB-INF classes folder.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Pratap A.K
  • 4,337
  • 11
  • 42
  • 79
0

The error comes because the server is not able to find correct path for struts.xml . Its better to put the struts.xml in parallel to src folder or in WEB-INF/classes.