所以,我的场景如下。
我的struts.xml
<action name="newInfo" class="org.blog.controller.NewInfo">
<result type="tiles" name="success">NewInfo</result>
</action>
<action name="postComment" class="org.blog.controller.CommentController">
<result type="redirectAction" name="success">newInfo?id=${articleId}</result
<result type="redirect" name="input">newInfo.action?id=${articleId}</result>
</action>
CommentController.java
public void validate() {
if(getName().length() == 0)
addFieldError("name", "Name is required");
if(getEmail().length() == 0)
addFieldError("email", "Email is required");
if(getCurrentURL().length() == 0)
addFieldError("website", "Website is required");
if(hasFieldErrors())
System.out.println("Field error.");
}
当前,页面结果是文章页面,带有“字段错误”,但页面没有显示任何字段错误。 那么,有没有解决方案来解决它?
答案 0 :(得分:0)
将type =“redirect”更改为type =“chain”,请参阅:http://struts.apache.org/2.0.14/docs/result-types.html了解详情。
答案 1 :(得分:0)
试试这个:
<action name="postComment" class="org.blog.controller.CommentController">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result type="redirectAction" name="success">newInfo?id=${articleId}</result
<result type="tiles" name="input">NewInfo</result>
</action>