Pravin
Pravin

Reputation: 645

The requested resource is not available in struts2 when action class is configured in struts.xml

I've tried to create a new action class and add it to struts.xml, the action class successfully get compiled but when I run tomcat it shows The requested resource is not available 404 error on index page itself.

CreateUser.jsp

<s:form action = "CreateUserAction" >
    <s:textfield name = "name" label = "Name" />
    <s:textfield name = "userName" label = "User Name" />
    <s:submit value = "Register" />
</s:form>

CreateUserAction.java

public String execute() {
    setMessage("Hello " + getUserName());
    return "SUCCESS";
}

Struts.xml

<package name="default" extends="struts-default">
    <action name="CreateUserAction" class="com.ecommerce.action.CreateUserAction">
    <result name="SUCCESS">/success.jsp</result>
    </action>
</package>

Upvotes: 2

Views: 16087

Answers (2)

Mithun Mathew
Mithun Mathew

Reputation: 11

for the above issue:"The requested resource is not available in struts2 when action class is configured in struts.xml" I have a suggestion.

Copy and paste all the external jars in in the folder lib(WebContent-->WEB-INF-->lib) remove all external jars from Build path (Project -->buildpath-->Configure Build path)

I found this solution is working fine for eclipse Luna with Tomacat 7

Upvotes: 0

Roman C
Roman C

Reputation: 1

Actions in Struts2 are mapped to the URLs that are built from the configuration. When the url of the request match the action name and namespace then it is executed, otherwise error code 404 is returned by the dispatcher. Struts2 is implemented as a filter and it's looking for the requests that are mapped in it's configuration. For example if I want it to filter all URLs I will write in web.xml

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
</filter>
 <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

If you say the error 404 on index page itself, then you should ask yourself which URL corresponds to it and what action is mapped via configuration to that URL. If you need more detailed picture of what configuration is and what URLs you could enter to execute an action install the config-browser plugin.

Upvotes: 4

Related Questions