在struts-config.xml中加了 <action path="/custmanager"
name="custmanagerform"
input="/main_add_cust.jsp"
type="com.nczxkj.struts.action.CustManagerAction"
scope="request"
parameter="method">
<forward name="maint" path="/main_custmanager.jsp"/>
<forward name="loadmanager" path="/main_add_cust.jsp"></forward>
</action>
验证的的代码都配置好啦
在CustManagerAction(继承DispatchAction)中有个change方法,有个add方法。还有个main_add_cust.jsp增加客户页面,也是要请求验证的页面。不管我进入custmanager.do?method=change还是custmanager.do方法都会直接进入main_add_cust.jsp页面,并且提交main_add_cust.jsp按钮时没有显示任何出错信息。
注:只要我一取消验证功能,点击进入custmanager.do?method=change时都会进入action指定的页面不会进入main_add_cust.jsp页面。
  现在向各位大师求救啊!  这个问题折腾我2天啦  要死了

解决方案 »

  1.   

    首先,检查下你的跳转是否正确再次,你既然是继承DispatchAction的话,最好干掉execute方法。。在一个最好重新发布部署下。
      

  2.   

    action默认的validate为true,会对每个方法进行校验的.你访问custmanager.do?method=change
    这个路径的时候,也会对数据进行校验的,这个时候连数据都没有,肯定通不过的。
    解决方法可以这样:<action validate="false">,手动对调用form的校验方法,只对需要校验的方法
    进行校验//当然这个是对写在actionForm中validate方法解决的办法.
    配置文件中的校验暂时没研究
      

  3.   

    action要继承DispatchAction的
    然后validate=true,这样就能验证后再进action了
      

  4.   

    你的Action是如何写的?你是想用getParameter决定调用哪个方法?
    换一下吧,你继承这个类MappingDispatchAction
    然后为每一个方法都写一个配置,这样好看点。你的问题是因为验证没通过吧,你的input属性的Value就是:/main_add_cust.jsp
    验证不通过,就自动路到这里去了
      

  5.   

    可以声明两个action节点
    1. 不进行验证
        <action path="/custmanager"
                name="custmanagerform"
                input="/main_add_cust.jsp"
                type="com.nczxkj.struts.action.CustManagerAction"
                scope="request"
                parameter="method"
                validate="false">
                <forward name="maint" path="/main_custmanager.jsp"/>
                <forward name="loadmanager" path="/main_add_cust.jsp"></forward>
        </action>
    2. 需要验证
        <action path="/custmanagerCheck"
                name="custmanagerform"
                input="/main_add_cust.jsp"
                type="com.nczxkj.struts.action.CustManagerAction"
                scope="request"
                parameter="method"
                validate="true">
                <forward name="maint" path="/main_custmanager.jsp"/>
                <forward name="loadmanager" path="/main_add_cust.jsp"></forward>
        </action>
      

  6.   

    3楼的 手动对调用form的校验方法,只对需要校验的方法 
    进行校验//当然这个是对写在actionForm中validate方法解决的办法. 我没弄明白能不能详细点哦
    还有6楼的 我也考虑过你这种方法,不过这样的话配置量就增加啦  这还只是一个action,却要分为2个解决 那要是有好多这样的action呢  那不要增加同等数量的action了???
      

  7.   

    唉 .....  就没有人帮我解决么   唉 ...  我不想吧一个action分为2个啊......soso....
      

  8.   

    首先你的CustManagerAction中应该去掉execute()这个方法,只要有这个方法在,你写的其他任何方法将没有效果String forwardname="";//这个根据你的验证判断来设置它对应在struts-config.xml中的forward的name的值
    你的ActionForward forward=mapping.findForward(forwardname);return forward;//这个很关键,例如不管前面你如何如何判断而你的forward都是mapping.findForward("maint");的话你的页面肯定最后是转向于/main_custmanager.jsp
    你在验证的时候判断有问题,你最好把你的action代码贴出来注释写好,大家才能看明白!
      

  9.   

    Action、ActionForm配置:<form-bean name="custmanagerform" type="com.nczxkj.struts.form.CustManagerForm"/> <action path="/custmanager"
    name="custmanagerform"
    type="com.nczxkj.struts.action.CustManagerAction"
    scope="request"
    parameter="method">
    <forward name="maint" path="/main_custmanager.jsp"/>
    <forward name="loadmanager" path="/main_add_cust.jsp"></forward>
    </action>
    CustManagerForm.java中验证代码:public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) { ActionErrors errors=new ActionErrors();
                    //cust_name为客户名
    if(cust_name==null || cust_name.equals("")){
    errors.add("cust_name", new ActionMessage("客户名不能为空 "));
    }
    return errors;
    }CustAction.java中代码:public class CustManagerAction  extends DispatchAction{
    //默认时跳转到页面
    protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    ActionForward forward=new ActionForward("/custmanager.do?method=custmanager");
    return forward;
    }
    //显示客户信息
    public ActionForward custmanager(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    CustDao custdao=new ExcuteCustDao();
    ExcuteManagerDao emd =new ExcuteManagerDao(custdao);
    List list=emd.manager();
    request.setAttribute("list", list);
    return mapping.findForward("maint");
    }
    //增加客户信息
    public ActionForward add(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    ActionForward forward=new ActionForward("/custmanager.do?method=custmanager");
    return forward;
    }
    }main_add_cust.jsp中代码:<form id="form1" name="form1" method="post" action="custmanager.do?method=add">
      <table width="80%" border="1" align="center" cellpadding="0" cellspacing="0" class="main_5">
        <tr>
          <th width="150" bgcolor="#6ec2fd">客户名</th>
          <td width="32%"><label>
            <input type="text" name="cust_name" /><input type="button" onclick="check()" value="检测客户名"/><html:errors property="cust_name"/>
          </label></td>
          <th width="150" bgcolor="#6ec2fd">客户经理</th>
          <td width="40%">
          <input type="text" name="cust_mgr" />
          </td>
        </tr>
        <tr>
          <th width="150" bgcolor="#6ec2fd">客户地址</th>
          <td><label>
            <input type="text" name="address"/>
          </label></td>
          <th width="150" bgcolor="#6ec2fd">管理人</th>
          <td><label>
        
          </label></td>
        </tr>
        <tr>
          <td colspan="2" align="right">
          <blockquote><input type="submit" value="提交"></blockquote>
          </td>
          <td colspan="2" align="left">
          <input type="reset" value="重置"/>
          </td>
        </tr>
      </table>
      <br />
    </form>注:没使用表单验证的情况下,一切跳转都正常,如果使用如上的情况,点击提交按钮,不会打印“客户名不能为空”信息 ,直接跳转到main_custmanager.jsp页面
    如果在action中加input="/main_add_cust.jsp"则会出现no input 等信息。当然如果把这个action分开来,验证请求的页面分一个action是可以的,但可不可以不用分开就能验证的啊
      

  10.   

    LZ 你验证为什么要搞的那么复杂呢?
    你就在你的DispatchAction的方法总验证不行吗?
    例如 if(cust_name==null || cust_name.equals("")){
              request.setAttribute("msg","客户名不能为空");
    }    
      

  11.   

    建议lz看看验证框架,
    针对同一个formbean配置不同的验证方案。Configuring the Validator to perform form validation is easy. 1.The ActionForm bean must extend ValidatorForm. 
    2.The form's JSP must include the <html:javascript> tag for client side validation. 
    3.You must define the validation rules in an xml file like this: 
    <form-validation>
    <formset>
    <form name="logonForm">
      <field property="username" depends="required">
        <msg name="required" key="error.username"/>
      </field>
    </form>
    </formset>
    </form-validation>
    4.The msg element points to the message resource key to use when generating the error message. 
    5.Lastly, you must enable the ValidatorPlugin in the struts-config.xml file like this: 
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property
    property="pathnames"
    value="/org/apache/struts/validator/validator-rules.xml,
        /WEB-INF/validation.xml"/>
    </plug-in>Note: If your required form property is one of the Java object representations of primitive types (ie. java.lang.Integer), you must set the ActionServlet's convertNull init. parameter to true. Failing to do this will result in the required validation not being performed on that field because it will default to 0. For more about the Struts Validator, see the Developers Guide.
      

  12.   

    13楼的  像你所说放在action里面那还要validator框架干什么呢。要考虑耦合  耦合啊....
    14楼的  你说的是用validator验证框架验证 你的方法我也用过了  不过出现的问题和现在用的一样 我现在用的是表单验证啊
      

  13.   

    如果FormBean的校验开关打开了,要考虑到,验证不通过必须而且只能有一个input指定的jsp页面
    看了半天,lz的需求好像是2个jsp页面对同一个FormBean进行验证
    这样的话,验证失败的话,只能跳到你指定的input的jsp页面
    俺现在只会这样做:
    1)合并jsp页面,把两个页面整合成一个jsp
    2)对应2个jsp配置2个Action。
      

  14.   

    两个用一个form也是一样的嘛 增加一个用于区别的属性attrbute,分别设定一个值,就行了,就相当于在用两个formBean