Struts的ActionForm问题

我的程序感觉没有调用validate();
每次跳转都是显示info的内容,而不是经过validate()判断是否符合;

ActionForm:

 package form;

import javax.servlet.ServletRequest;
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;

import jdk.nashorn.internal.ir.RuntimeNode.Request;

public class HelloForm extends ActionForm{
    private String info;

    @Override
    public ActionErrors validate(ActionMapping mapping, ServletRequest req) {
        ActionErrors errors = new ActionErrors();

        if(this.info == null || info.equals("")){
            errors.add("info", new ActionMessage("error.info"));
        }
        return errors;
    }

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {

    }
    public String getInfo() {
        return info;
    }
    public void setInfo(String info) {
        this.info = info;
    }


}

JSP:

 <%@ page language="java" pageEncoding="GBK"%>

<%@ taglib uri="struts/bean" prefix="bean"%>
<%@ taglib uri="struts/html" prefix="html"%>
<%@ taglib uri="struts/logic" prefix="logic"%>
<html:html lang="true">
<head>
    <html:base />
    <title>hello.jsp</title>
</head>
<body>
    <html:errors/>
    <logic:present name="msg" scope="request">
        <h2>${msg}</h2>
    </logic:present>
    <html:form action="hello.do" method="post">
        请输入信息:<html:text property="info"></html:text>
        <html:submit value="显示"></html:submit>
    </html:form>
</body>
</html:html>

Struts-config:

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
    <form-beans>
        <form-bean name="helloForm"
            type="form.HelloForm" />
    </form-beans>

    <global-exceptions />
    <global-forwards />
    <action-mappings>
        <action attribute="helloForm" input="/hello.jsp"
            name="helloForm" path="/hello" scope="request"
            type="action.HelloAction">
            <forward name="show" path="/hello.jsp"></forward>
        </action>
    </action-mappings>

    <message-resources parameter="action.ApplicationResources" />
</struts-config>

查看全部
HKINQ
HKINQ
2015/09/16 15:43
  • struts
  • 点赞
  • 收藏
  • 回答
    私信

1个回复