Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts Hello world example : There is no Action mapped for namespace [/] and action name error

i am absolute beginner to Struts2. I am tying to follow tutorials on struts web site. i followed this tutorial. i have some trouble with it. i created dynamic web project on eclipse. Then i followed the tutorial. However when i run the example i get the following error.

There is no Action mapped for namespace [/] and action name [hello] associated with context path [/Hello_World_Struts_2]. - [unknown location]

i have the following directory structure

enter image description here

And my struts.xml file is

 <?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.devMode" value="true" />

  <package name="basicstruts2" extends="struts-default" namespace="/">

  <action name="index">
    <result>/index.jsp</result>
  </action>

  <action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
    <result name="SUCCESS">/HelloWorld.jsp</result>
  </action>

</package>

</struts>

thanks for your responses.

like image 695
erencan Avatar asked Jan 24 '12 17:01

erencan


3 Answers

The struts.xml configuration file needs to be on the classpath (as opposed to in WEB-INF).

The linked tutorial assumes a Maven build and states the struts.xml file should go in src/main/resources, which will be included in the classpath in Maven builds. Since you're ignoring that part, you'll likely want to put it in the root of your source directory.

like image 135
Dave Newton Avatar answered Dec 09 '22 20:12

Dave Newton


You have to create a classes/ folder under WEB-INF/ and put in your struts.xml file!

like image 39
Riadh Avatar answered Dec 09 '22 19:12

Riadh


Right click the project. Go to properties deployment build path and add all .jar files to /WEB-INF/lib.
Then you shouldn't get this error.

struts.xml should be located under directory: src/struts.xml..

And WEB-INF/web.xml you we need to configure the struts based on filter..

like image 26
Raviteja Avatar answered Dec 09 '22 20:12

Raviteja