1

Hi all I'm having problems using Struts 2 Annotated Actions

In my pom.xml I have:

<!-- STRUTS2 annotation -->
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-convention-plugin</artifactId>
    <version>2.3.16.3</version>
</dependency>

<!-- STRUTS2 SPRING integration -->
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-spring-plugin</artifactId>
    <version>2.3.15.1</version>
</dependency> 

in my web.xml:

<filter>
  <filter-name>struts2</filter-name>
    <filter-class>com.agiletec.apsadmin.system.dispatcher.StrutsPrepareAndExecuteFilter</filter-class>
      <init-param>
      <param-name>struts.devMode</param-name>
      <param-value>true</param-value>        
      </init-param>
      <init-param>
      <param-name>struts.objectFactory</param-name>
      <param-value>spring</param-value>        
      </init-param>        
<init-param>
    <param-name>actionPackages</param-name>
    <param-value>it.aicof.projects.openMED.aps.internalservlet.actions</param-value>
</init-param>          
</filter>  
  
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/do/*</url-pattern>
</filter-mapping>
<filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/struts/*</url-pattern>
</filter-mapping>

I have two action classes:

@Namespace("/budget")
@SuppressWarnings("serial")
public class BudgetAction extends BaseAction {
    
    @Action(value = "/start", results = { @Result(name = "success", location = "/WEB-INF/openmed/aps/jsp/internalservlet/budget/budget.jsp") })
    public String start(){
.......


@Namespace("/upload")
@SuppressWarnings("serial")
public class UploadAction extends BaseAction {

    @Action(value = "/init", results = {
        @Result(name = "success", location = "/WEB-INF/openmed/aps/jsp/internalservlet/upload/upload.jsp")})
    public String init() {
        .....

if I call the first one http://localhost:8080/openMED/do/budget/start.action all works but when I call the second one http://localhost:8080/openMED/do/upload/init.action i get this error

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

    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:553)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:744)

What's wrong? Two classes are configured in the same way.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Andrea
  • 190
  • 1
  • 20

1 Answers1

1

According to the error message

2014-07-18 15:49:15,454 - ERROR - Dispatcher - Exception occurred during processing request: There is no Action mapped for namespace [/do] and action name [init] associated with context path [/openMED]. - [unknown location].

you have used url /openMED/do/upload/init.action but your action is mapped to the namespace /upload. A namespace is a path from the context path to action name. You can find more information about namespace configuration. You can also look at this example to better understand namespaces concept.

You should change action mapping

@Namespace("/do/upload")
@SuppressWarnings("serial")
public class UploadAction extends BaseAction {

@Action(value = "init", results = {@Result(name = "success", location = "/WEB-INF/openmed/aps/jsp/internalservlet/upload/upload.jsp")})
public String init() {
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Roman.. i realized the problem was not i was thinking to... so i change the question to try to be more specific – Andrea Jul 23 '14 at 19:04
  • Updated to you changes. – Roman C Jul 23 '14 at 19:28
  • ok but the other one is /openMED/do/budget/start.action same pattern as /openMED/do/upload/init.action .... and it works correctly. So.. why the first one works and the other one not? – Andrea Jul 23 '14 at 22:03
  • You might have other action mapping. You didn't post `struts.xml`. – Roman C Jul 24 '14 at 09:04
  • i have not a struts.xml.... maybe i found the problem, it was my mistake. i mapped actions path in web.xml as `it.aicof.projects.openMED.aps.internalservlet.actions` but the action not working was in path `it.aicof.projects.openMED.aps.internalservlet` so it was not recognized as action by struts. I'll try to move it in the right path – Andrea Jul 24 '14 at 10:04