action源码:package com.tonespro.struts.action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
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.tonespro.database.ConUserInfo;
import com.tonespro.struts.form.LoginForm;
public class LoginAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

String userid = "";
String password = "";
String isOk = "";

LoginForm loginForm = (LoginForm) form;
userid = loginForm.getUserid();
password = loginForm.getPassword();

ActionMessages message = new ActionMessages();
ConUserInfo userinfo = new ConUserInfo();
isOk = userinfo.checkLogin(userid, password);

if (isOk.equals("fail")){
message.add("err",new ActionMessage("12312"));
this.saveMessages(request, message);
}

return ( mapping.findForward(isOk) );
}
}
jsp源码:<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'loginFail.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
    <h3>html:errors/><h3>
  </body>
</html:html>

解决方案 »

  1.   

    马虎了吧:
    <h3>html:errors/><h3>  ——> <h3><html:errors/><h3>
      

  2.   

    把这个message.add("err",new ActionMessage("12312"));
    改成message.add("err",new ActionMessage("12312",false));试试
      

  3.   

    message.add("err",new ActionMessage("12312"));
    y有没有对应国际资源化文件。
    没有的话用
    message.add("err",new ActionMessage("12312",false));
    页面用<html:messages/>试试看。
      

  4.   

    谢谢各位!已经解决了。 原来struts1.3版本和struts1.2对这个的引用不太一样,正确的应该是这样:action:ActionMessages msgs = new ActionMessages();
    msgs.add('property1', new ActionMessage('userRegistration.password.nomatch'));  
    request.setAttribute(Globals.MESSAGE_KEY, msgs); jsp:<html:messages id='message' message='true' /><bean:write name='message'/> properties:userRegistration.password.nomatch=\u5931\u8d25 show:失败