Struts 작업의 여러 진입점(Migration Struts 2.2.3 -> 2.3.1)
문제
struts.xml에 작업이 있습니다.
<action name="reprint" class="reprintAction">
<result name="success" type="redirectAction">
<param name="actionName">reprint</param>
<param name="namespace">/x</param>
<param name="errorFlag">${errorFlag}</param>
<param name="message">${message}</param>
</result>
<result name="view">/jsp/reprintOverview.jsp</result>
</action>
JSP:
<s:form action="reprint">
<s:select name="selectedPdfPrinter" list="shopPdfPrinterList" listKey="deviceId" listValue="deviceId" theme="simple"/>
<s:submit value="Print" theme="simple" method="shopPdfReprint"/>
</s:form>
여러 개의 양식 요소가 모두 하나의 작업에 바인딩되어 있습니다.각 양식에는 별도의 제출 버튼이 있습니다. method
(예:"shopPdfReprint").각 method
해당 클래스의 메소드에 매핑됩니다.
Struts 2.2.3에서는 모든 것이 잘 작동합니다.그러나 2.3.1로 마이그레이션한 후에는 메소드 매핑이 작동하지 않습니다.대신 해당 메서드를 호출합니다(예:"shopPdfReprint"), execute
-클래스의 메소드가 호출됩니다.
나는 문서를 보았지만 불행히도 단서가없고, 2.3.1에 적응하는 방법을 찾지 못했습니까?도움을 주시면 감사하겠습니다 :]
해결책
이는 DMI를 끄었기 때문에 발생합니다.그만큼 method
속성은 보안 수정 사항을 다시 보낸 후에도 이전과 마찬가지로 제출 태그와 함께 작동합니다.상수를 사용하여 DMI를 활성화합니다.
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
작동하지 않으면 알려주세요.
다른 팁
누구든지 Struts 2.5로 이동하거나 작업하는 경우 struts.xml을 사용하여 작업을 매핑할 필요가 없습니다.Strtus 2.5는 주석 기반이므로 액션 클래스 개발자는 주석을 사용하여 단일 클래스 내에서 여러 액션을 매핑할 수 있습니다.
이 링크가 이전 Struts 버전에서 Struts 2.5 버전으로 도움이 될 수 있습니다.
https://struts.apache.org/docs/struts-23-to-25-migration.html
다음은 간단한 데모 코드입니다.
package com.stsh.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
import com.stsh.intercepter.AuthRequired;
@ParentPackage(value="default")
@Namespace(value="/dashboard")
public class DashboardAction extends ActionSupport implements AuthRequired{
private static final long serialVersionUID = 1L;
@Action(value = "home", results = { @Result(name = "success", location = "dashboard.tiles", type = "tiles") })
public String dashboard(){
return "success";
}
}