javastruts2struts1

Running Struts 1 & Struts 2


I'm trying to get an application running using both Struts1 and Struts2. Reason being it's being migrated but there is a lot of Struts1 which we want to do bit by bit not big bang... I know this can be done

Anyhow I cannot get my S2 filter to pick up my URL and no errors are being given when I access a *.action URL ! All S1 pages still work fine. My web XML contains the S2 config...

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
</filter-mapping>

and the S1 servlet

<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

I've also set up a simple TestStruts2Action class extending Action that literally just had a syso in it to prove it reached the action. XMLconfig'

  <package name="main" extends="struts-default">
      <action name="testStruts2" class="com.myclass.TestStruts2Action">
         <result name="success">test/testStruts2.jsp</result>
      </action>
  </package>

All I get is the applications 404 page when hitting the URL /MyApp/testStruts2.action

My JSP is literally just a HelloWorld example and held under test/testStruts2.jsp

Any ideas ? With no errors during start or logged when I hit the URLs I'm at a loss as to what to try next...

Attempted adding namespaces


Solution

  • Ok figured what I was doing wrong...

    My struts.xml file was placed alongside the old struts-config file in WEB-INF and the new filter was not reading it. I used this post to figure that one out and amended my declaration of my filter in web.xml too

    <filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
      <init-param>
        <param-name>config</param-name>
        <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
      </init-param>
    

    However this took my attention

    @AleksandrM

    'Also the order in which you define xml files is important as well. E.g. You cannot extend struts-default package (from struts-default.xml) in your struts.xml if it isn't loaded yet.'

    @AleksandrM Do you mean if you move the struts.xml location you can't extend the struts-default within the package declarations ??