0

Facing the Ognl expression issue while upgrading Struts from 2.3.35 to 2.5.22 Below is the action mapping code in my struts.xml

<action name="studentDetail"
    class="fn.college.action.StudentDetailAction">
    <interceptor-ref name="abcStack" />
    <param name="rollno">${rollno}</param>
    <result>/WEB-INF/pages/studentViewPage.jsp</result>
    <result name="showPreRegisteredAccount" type="redirectAction">showPreRegisteredAccount?studentId=${studentId}</result>
    <result name="error">/WEB-INF/pages/index.jsp</result>
</action>

Done the all required changes mentioned in https://cwiki.apache.org/confluence/display/WW/Struts+2.3+to+2.5+migration migration page.

Issue: When we search for the student record by passing rollno in url it can't resolve the ${rollno} in interceptor but when we give static value instead ${rollno} it works fine.

Struts 2.3 to 2.5 migration - Apache Struts 2 Wiki - Apache Software Foundation https://cwiki.apache.org

Edit:

In our scenario we have action chaining defined in struts.xml as per question. now when we hit url like "http://localhost:8080/student/login.jsp". we have some search filed in JSP to search student data by different criteria like Student Name, Student Roll No. Now when we enter student name to search , it calls one StudentSearchAction and in that we first gets fetch student roll no from student name and we are building url in Action class like "http://localhost:8080/studentDetail?rollno=5" and set this url in one of the setter method lets say "redirectActionUrl" and return static string "studentDetail".

now as per action configured as above, it will map "studentDetail" name to result name and it will redirect our action with that redirection action url

<action name="studentSearch" class="fn.college.action.StudentSearchAction" method="getStudentInfo">
    <result>/WEB-INF/pages/studentResultPage.jsp</result>
    <result name="index">/WEB-INF/pages/index.jsp</result>
    <result name="preRegisteredAccountSearchPage" type="redirectAction">preRegisteredAccountSearchPage</result>
    <result name="studentviewpage">/WEB-INF/pages/studentViewPage.jsp</result>
    <result name="studentresultpage">/WEB-INF/pages/studentResultPage.jsp</result>
    <result name="studentDetail" type="redirectAction">${redirectActionUrl}</result>
</action>

now in action mapping for studentDetail we have used param tag to populate that roll no value dynamically using ${} in action tag. in our interceptor we first get action of StudentDetail like and we are calling StudentDetailAction.getRollno it actually gives value as ${rollno} instead of that real value.

Intercepter code where we getting ${rollno} instead it's actual value.

studentId = studentManager.getActiveOrDeactiveStudentIdByRollNo(studentDetailAction.getRollNo(), null);

We have debugged ParametersInterceptor class and it seems that populates param rollno with value ${rollno} and it's not populating actual value

Note: It was working fine with struts 2.3.x version but after upgrading 2.5.22 it's not working

  • It's not clear what is the issue? Parameters that passed from the URL are request params. They populate the action as usual with the `params` interceptor. – Roman C Nov 10 '20 at 08:43
  • Hi, @roman-c added more details for clarity, thanks in advance! – Dixit Jain Nov 12 '20 at 12:10
  • As I said before you have configured *static* parameter in the action config. It's not the parameter you sending in URL. Seems you complete ignoring what I'm saying. For your further investigation of parameters processing see [this](https://stackoverflow.com/a/20327148/573032) answer. – Roman C Nov 13 '20 at 07:37

0 Answers0