页面
<%@ page contentType="text/html; charset=GBK" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<html>
<head>
<title>
登录
</title>
</head>
<body bgcolor="#ffffff">
<html:errors property="org.apache.struts.action.GLOBAL_MESSAGE"/>
<html:form action="/adminLogin.do" focus="userName">
<html:text property="userName" size="16" maxlength="16"/>
<bean:message key="form.userName.length" />
<br>
<html:submit property="submit" value="Submit"/>
</html:form>
</body>
</html>
=====================
在FormBean里
package Bean;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class AdminLoginForm extends ActionForm {
private String userName;
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
ActionErrors errors = new ActionErrors();
try{
if ( (userName == null) || (userName.length() < 1))
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("form.userName.length"));
}
catch(Exception e){
System.out.println("======here");
}
return errors;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
this.userName=null;
}
}
为什么我在文本框不输入任何东西就提交,就会出现这种错误提示
--------------------------------------------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.ClassCastException
at org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
at org.apache.jsp.Admin_0005flogin$jsp._jspService(Admin_0005flogin$jsp.java:80)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)