ActionForm源码package com.xj.guestbook.form;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;public class LoginForm extends ActionForm {

private static final long serialVersionUID = 1L;
private String url;
private String password;
private String userName; public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();

if (userName == null || userName.length() <= 0) {
errors.add("userNameError", new ActionMessage("error.name.null"));
} else if (userName.length() <= 2) {
errors.add("userNameError", new ActionMessage("error.name.small"));
} if (password == null || password.length() <= 0) {
errors.add("passwordError", new ActionMessage(
"error.password.null"));
} else if (password.length() <= 5) {
errors.add("passwordError", new ActionMessage(
"error.password.small"));
} return errors;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.userName=null;
this.password=null;
this.url=null;
} public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setUrl(String url) {
this.url = url;
}

public String getUrl() {
return this.url;
}
}

解决方案 »

  1.   

    LoginAction源码package com.xj.guestbook.action;import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;import org.apache.struts.action.Action;
    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 com.xj.guestbook.Constants.Constants;
    import com.xj.guestbook.dao.UserInfoDAOImpl;
    import com.xj.guestbook.form.LoginForm;
    import com.xj.guestbook.po.UserInfoPo;
    import com.xj.guestbook.vo.UserInfoVo;public class LoginAction extends Action { public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{


    String userName =(String)((LoginForm) form).getUserName();
    String password = (String)((LoginForm) form).getPassword();

    UserInfoDAOImpl user=new UserInfoDAOImpl();

    UserInfoPo userInfo=user.Check(userName,password);

    if(userInfo==null){
    ActionErrors errors = new ActionErrors();
    errors.add("userNameError", new ActionMessage(
    "error.namepassword"));
    saveErrors(request, errors); return mapping.getInputForward();
    }
    //HttpSession session=request.getHttpSession(); 
    request.setAttribute("userInfo",userInfo);
    return mapping.findForward(Constants.INDEX_KEY);
    }}
      

  2.   

    struts-config.xml没有错呀<action-mappings >
        <action path="/login" 
        type="com.xj.guestbook.action.LoginAction" 
        name="LoginForm"
        scope="request"
        validate="true"
        input="/login.jsp">
        </action>
      </action-mappings>
      

  3.   

    <form-beans >
        <form-bean name="LoginForm" type="com.xj.guestbook.form.LoginForm" />
      </form-beans>
      

  4.   

    <%@ page contentType="text/html;charset=gb2312"%><%@ taglib prefix="tiles" uri="/WEB-INF/struts-tiles.tld"%>
    <%@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld"%>
    <%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld"%>
    <html>
    <head>
    <title>
    <bean:message key="label.title" />
    </title> <STYLE TYPE='text/css'>
    TD {table-layout :fixed; word-break :break-all}
    input.smallInput{border:1 solid black; border-bottom-color:#333399; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-VARIANT: normal; FONT-WEIGHT: normal; HEIGHT: 18px; LINE-HEIGHT: normal}
    input.buttonface{
    border:1 solid #ff6633;
    COLOR: #FFFFFF;
    FONT-SIZE: 9pt;
    FONT-STYLE: normal;
    FONT-VARIANT: normal;
    FONT-WEIGHT: normal;
    HEIGHT: 18px;
    LINE-HEIGHT: normal;
    background: #333399;
    }
    </STYLE>
    </head> <body>
    <TABLE width="760" height="4" border="0" align="center">
    <TR>
    <TD height="1" colspan="3" align="center"">
    <%@include file="include/header.jsp"%>
    </TD>
    </TR>
    <TR>
    <TD height="1" colspan="3" align="right">


    </TD>
    </TR>
    <tr>
    <td>
    <html:form action="/login.do" method="post">

    <table width="550" border="0" align="center" bgcolor="#EEEEEE">
    <tr>
         <td height="21" align="center" colspan="2" bgcolor="#3A6EA5">
         <FONT size="2" color="#FFFFFF">
         <b>
         <bean:message key="label.login"/>
         </b>
         </FONT>
         </td>
       </tr>
       <tr>
         <td align="center" colspan="2">
         <font size="2">
         <br>
         <bean:message key="label.login.register1"/>
        
        
         <bean:message key="label.login.register2"/>
        
         </font>
         </td>
       </tr>
       <tr>
         <td width="40%" align="right">
         <font size="2">
         <b>
         <bean:message key="label.username"/>:
         </b>
         </font>
         </td>
         <td>
         <html:text property="userName" maxlength="17" styleClass="smallInput"/>
         <FONT size="2" color="red">
         <b>
         <html:errors bundle="ERROR_RESOURCES" property="userNameError"/>
         </b>
         </FONT>
         </td>
       </tr>
       <tr>
         <td width="40%" align="right">
         <FONT size="2">
         <b>
         <bean:message key="label.password"/>:
         </b>
         </FONT>
         </td>
         <td>
         <html:password property="password" maxlength="17" size="20" styleClass="smallInput"/>
         <FONT siae="2" color="red">
         <b>
         <html:errors bundle="ERROR_RESOURCES" property="passwordError"/>
         </b>
         </FONT>
         </td>
       </tr>
       <tr>
         <td colspan="2">
         <html:submit styleClass="buttonface">
         <bean:message key="label.login"/>
         </html:submit>
         </td>
       </tr>
    </table>
    </html:form>
    </td>
    </TR>
    <TR>
    <TD height="1" colspan="3" align="center">
    <%@include file="include/footer.jsp"%>
    </TD>
    </TR>
    </TABLE>
    </body>
    </html>
      

  5.   

    配置文件出错了
     <action-mappings>
            <action attribute="LoginForm" input="/login.jsp" name="LoginForm" path="/login" type="com.xj.guestbook.action.LoginAction">
                <forward name="..." path="....." />
            </action>
     </action-mappings>
      

  6.   

    还有
    <html:text property="userName" name= "LoginForm" maxlength="17" styleClass="smallInput"/>
      

  7.   

    <forward name="..." path="....." />
     你写了吗?
    在你的配置文件都没看到这个呢
      

  8.   

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><struts-config>
      <data-sources />
      <form-beans >
        <form-bean name="LoginForm" type="com.xj.guestbook.form.LoginForm" />
      </form-beans>
      <global-exceptions />
      <global-forwards>
       <forward name="index" path="/index.jsp" redirect="true" />
       <forward name="login" path="/login.jsp" redirect="true" />
      </global-forwards>
      <action-mappings >
        <action attribute="LoginForm" input="/login.jsp" name="LoginForm" path="/login" type="com.xj.guestbook.action.LoginAction"/>
      </action-mappings>
     
      <message-resources parameter="com.xj.guestbook.MessageResources" />
      <message-resources key="IMAGE_RESOURCES" parameter="com.xj.guestbook.ImageResources" />
      <message-resources key="ERROR_RESOURCES" parameter="com.xj.guestbook.ErrorMessageResources" /></struts-config>
      

  9.   


    1、这个是什么?
    Constants.INDEX_KEY2、path="/login.jsp" 的路径对不对?
      

  10.   

    Constants.INDEX_KEY 相当于indexpath="/login.jsp" 路径对我想多数是Action里的错误
      

  11.   


    ActionErrors errors = new ActionErrors();
    errors.add("userNameError", new ActionMessage(
    "error.namepassword"));
    saveErrors(request, errors);
    这里的问题我换了一个struts.jar包就可了