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

  • Do you get any errors on startup? Try adding `namespace="/"` to `package`. Which version of S2 are you using? – Aleksandr M Jun 05 '17 at 16:51
  • @AleksandrM tried adding namespace="/" and same... Using S2 2.5.10 Zero errors on start up and zero errors logged when I access the URL other thanmy 404 page not found ! I'm stumped – Dangerous Hamster Jun 06 '17 at 09:11

1 Answers1

2

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 ??

  • 1
    Would love to know how you got on migrating s1 to s2. Could you supply a link to your migration story? (am involved in an s1 to s2 project) – johnm Nov 21 '19 at 11:36
  • @johnm copmleted the project over a year and a half ago now and tbh I can't remember much, it's been banished in my memory as one to forget... What we done was found the commonalities between S1 & S2 then run a 'find and replace script' through the code to change everything - worked well too One thing I do remember is I used Generics to indicate what Form was present for each Action and used an abstract class to generate those forms on the fly in S2 alongside a reuse of the old forms validation methods etc... Sorry don't have anything external I can share :( – Dangerous Hamster Dec 11 '19 at 10:19