Ghetolay
Ghetolay

Reputation: 3342

Struts2 convention plugin (m2eclipse/geronimo)

Using convention-plugin seems really easy but im not able to make it work :(

I'm using struts2 version 2.2.3

I have a package named com.medicis.actions with a UserAction extending ActionSupport. I don't have any struts.xml file I have the convention-plugin depency set on my maven configuration (i also checked the generated war file) There is my web.xml :

<display-name>Starter</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext*.xml</param-value>
</context-param>

<!-- Filters -->
<filter>
    <filter-name>action2-cleanup</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter>
    <filter-name>action2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>action2-cleanup</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>action2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Listeners -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>jspSupportServlet</servlet-name>
    <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
    <load-on-startup>5</load-on-startup>
</servlet>

<!-- Welcome file lists -->
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>

I tried with and without the init param for the action2 filter:

<init-param>
   <param-name>actionPackages</param-name>
   <param-value>com.medicis.actions</param-value>
</init-param>

I have this property set on my struts.propertie file :

struts.action.extension=action

Still i'm unable to launch my action using localhost:8080/starter/user.action :

There is no Action mapped for namespace / and action name user

I really don't know what's going wrong, I even downloaded a simple example without any result either.

Could it be a configuration problem due to eclipse, m2eclipse, maven wtp or geronimo ???

If you need more information just tell me and i'll provide you that asap.

Upvotes: 0

Views: 1280

Answers (1)

darek
darek

Reputation: 301

  1. Create struts.properties in "src" folder
  2. Copy and paste code from below:

    struts.convention.package.locators = actions
    struts.convention.action.suffix = Controller
    struts.convention.action.mapAllMatches = true
    
  3. Create class called IndexController in com.example.actions

  4. Copy and paste code from below:

    package com.example.actions;
    
    import org.apache.struts2.interceptor.validation.SkipValidation;
    import org.apache.struts2.rest.DefaultHttpHeaders;
    import org.apache.struts2.rest.HttpHeaders;
    import com.opensymphony.xwork2.ActionSupport;
    
    public class UserController extends ActionSupport {
    
        public String index(){
            return SUCCESS
        }
    
    }
    

You also need to create jsp file in WEB-INF/content/user/index.jsp

Upvotes: 1

Related Questions