/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yourcompany.struts.action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;import com.yourcompany.struts.form.LoginForm;/** 
 * MyEclipse Struts
 * Creation date: 01-26-2010
 * 
 * XDoclet definition:
 * @struts.action path="/login" name="loginForm" input="/form/login.jsp" scope="request" validate="true"
 */
public class LoginAction extends Action {
/*
 * Generated Methods
 */ /** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
response.setCharacterEncoding("GBK");
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub

String userName = loginForm.getUserName();

ActionMessages errors = new ActionErrors();

if(!userName.equals("abc")) {
errors.add("userName", new ActionMessage("userName_wrong"));
this.saveMessages(request, errors);
return mapping.getInputForward();
}
return mapping.findForward("succ");

}
}
书上原来用的ActionErrors类,看了文档发现不能废弃了,改用了ActionMessages errors = new ActionErrors();,运行了一下在文本框后貌似没有出错信息,应该怎么改

解决方案 »

  1.   

    你的页面用了要显示 页面的错误信息的代码吗?
     </errors>
      

  2.   

    恩 用了
    <%@ page language="java" pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html>
    <head>
    <title>JSP for LoginForm form</title>
    </head>
    <body>
    <html:form action="/login">
    userName : <html:text property="userName" />
    <html:errors property="userName" />
    <br />
    <html:submit />
    <html:cancel />
    </html:form>
    </body>
    </html>
    ApplicationResources.properties# Resources for parameter 'com.yourcompany.struts.ApplicationResources'
    # Project Struts3.2.2
    userName_wrong = your username is wrong!~
      

  3.   

    <s:fielderror name=""></s:fielderror>