Struts 表单不验证问题 谢谢 !!
jsp提交之后不验证 好像根本没有到 ActionForm 大家看看
这是jsp
--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=GB2312"
pageEncoding="GB2312"
%>
<META http-equiv="Content-Type" content="text/html; charset=GB2312">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="../../../theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>Flow_add.jsp</TITLE>
</HEAD>
<BODY>
<html:form action="/flow">
<TABLE border="0">
<TBODY>
<TR>
<TH>seqno</TH>
<TD><html:text property="seqno" /></TD>
</TR>
<TR>
<TH>flowname</TH>
<TD>
<html:text property="flowname" />
</TD>
</TR>
<TR>
<TH>flowmemo</TH>
<TD><html:text property="flowmemo" /></TD>
</TR>
<TR>
<TH>validflag</TH>
<TD><html:text property="validflag" /></TD>
</TR>
<TR>
<TD>
<html:submit property="submit" value="Submit" />
</TD>
<TD><html:reset /></TD>
</TR>
</TBODY>
</TABLE>
</html:form>
</BODY>
</html:html>
-------------------
这是ActionForm
---------------------
package com.itown.decl.struts.forms;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* Form bean for a Struts application.
* Users may access 4 fields on this form:
* <ul>
* <li>validflag - [your comment here]
* <li>flowmemo - [your comment here]
* <li>flowname - [your comment here]
* <li>seqno - [your comment here]
* </ul>
* @version 1.0
* @author
*/
public class FlowActionForm extends ActionForm {
private String flowmemo = null;
private String validflag = null;
private String flowname = null;
private String seqno = null;
//System.out.println("--1->");
/**
* Get flowmemo
* @return String
*/
public String getFlowmemo() {
return flowmemo;
}
/**
* Set flowmemo
* @param <code>String</code>
*/
public void setFlowmemo(String f) {
this.flowmemo = f;
}
/**
* Get validflag
* @return String
*/
public String getValidflag() {
return validflag;
}
/**
* Set validflag
* @param <code>String</code>
*/
public void setValidflag(String v) {
this.validflag = v;
}
/**
* Get flowname
* @return String
*/
public String getFlowname() {
return flowname;
}
/**
* Set flowname
* @param <code>String</code>
*/
public void setFlowname(String f) {
this.flowname = f;
}
/**
* Get seqno
* @return String
*/
public String getSeqno() {
return seqno;
}
/**
* Set seqno
* @param <code>String</code>
*/
public void setSeqno(String s) {
this.seqno = s;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
// Reset values are provided as samples only. Change as appropriate.
flowmemo = null;
validflag = null;
flowname = null;
seqno = null;
System.out.println("in reset");
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
System.out.println("in validate");
// Validate the fields in your form, adding
// adding each error to this.errors as found, e.g.
// if ((field == null) || (field.length() == 0)) {
// errors.add("field", new org.apache.struts.action.ActionError("error.field.required"));
// }
// 输入数据校验!
if(flowname == null || flowname.length() == 0){
errors.add("flowname", new org.apache.struts.action.ActionError("error.login.nameerror!"));
System.out.println("in errors");
}
if(validflag == null || validflag.length() == 0){
errors.add("validflag", new org.apache.struts.action.ActionError("不能为空!"));
System.out.println("in errors");
}
if(seqno == null || seqno.length() == 0){
errors.add("seqno", new org.apache.struts.action.ActionError("不能为空!"));
System.out.println("in errors");
}
if(flowmemo == null || flowmemo.length() == 0){
errors.add("flowmemo", new org.apache.struts.action.ActionError("不能为空!"));
System.out.println("in errors");
}
return errors;
}
}
-------------------------
这是config.xml
---------------------
<?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>
</data-sources>
<!-- 表单 Bean -->
<!-- 全局异常 -->
<form-beans>
<form-bean name="SampleActionForm" type="com.itown.struts.forms.SampleActionForm">
</form-bean>
<form-bean name="FlowActionForm" type="com.itown.decl.struts.forms.FlowActionForm">
</form-bean>
</form-beans>
<global-exceptions>
</global-exceptions>
<!-- 全局转发 -->
<global-forwards>
</global-forwards>
<!-- 操作映射 -->
<!-- 消息资源 -->
<action-mappings>
<action name="SampleActionForm" path="/sample" scope="request" type="com.itown.struts.actions.SampleAction" input="sample.jsp">
</action>
<action name="FlowActionForm" path="/flow" scope="request" type="com.itown.decl.struts.actions.FlowAction" input="Flow_add.jsp" validate="true">
</action>
</action-mappings>
</struts-config>
---------------------