Struts从2.3升级到2.5后,Ognl表达式不起作用

时间:2020-11-09 10:14:02

标签: struts2 ognl struts2-interceptors

在将Struts从2.3.35升级到2.5.22时面对Ognl表达式问题 下面是我的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>

完成https://cwiki.apache.org/confluence/display/WW/Struts+2.3+to+2.5+migration迁移页面中提到的所有必需的更改。

问题:当我们通过在URL中传递rollno来搜索学生记录时,它无法解析拦截器中的$ {rollno},但是当我们提供静态值而不是$ {rollno}时,它就可以正常工作。

从Struts 2.3到2.5的迁移-Apache Struts 2 Wiki-Apache软件基金会 https://cwiki.apache.org

编辑:

在我们的场景中,我们根据问题在struts.xml中定义了动作链接。现在,当我们点击“ http:// localhost:8080 / student / login.jsp”之类的网址时。我们在JSP中进行了一些搜索,以按照不同的条件(例如,学生名,学生名册编号)搜索学生数据。现在,当我们输入学生名进行搜索时,它会调用一个StudentSearchAction,并且首先从学生名中获取学生名册编号,然后在Action类中构建网址,例如“ http:// localhost:8080 / studentDetail?rollno = 5”,并在其中一种设置方法中设置此网址,例如说“ redirectActionUrl”,并返回静态字符串“ studentDetail”。

现在按照上述配置的操作,它将“ studentDetail”名称映射到结果名称,并将使用该重定向操作网址重定向我们的操作

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

现在,针对StudentDetail的动作映射中,我们已使用param标记在动作标记中使用$ {}动态填充了没有滚动值。在拦截器中,我们首先获得类似于StudentDetail的操作,然后我们将其称为StudentDetailAction.getRollno,它实际上给出的值为$ {rollno}而不是实际值。

我们在其中获得$ {rollno}的拦截器代码是它的实际值。

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

我们已经调试了ParametersInterceptor类,似乎使用值$ {rollno}填充了参数rollno,并且没有填充实际值

注意:在struts 2.3.x版本上可以正常工作,但是在升级2.5.22之后不能正常工作

0 个答案:

没有答案