不知道那个机制
我的方法是这样的首先在form里实现reset()方法,把所有属性=null;
然后在action里,用完form后,做form.reset();OK

解决方案 »

  1.   

    是有一个Token,令牌,网上都有这样的资料,但是都不知道怎么使用,好 烦!
      

  2.   

    在Action类里面的execute里面
    写上
    this.saveToken(request);在提交的方法中

    if (!isTokenValid(request, true)) {
    //
    }
    进行判断是否重复提交
      

  3.   

    谢谢,但是,我感觉还form表单里面还得隐藏一些东西,
      

  4.   

    this.saveToken(request);
    后,表单里面会自动产生这样的隐藏输入表单域
    <input type="hidden" name="org.apache.struts.taglib.html.TOKEN" value="6602b5d7c9e511229ad845823b2becd2">
      

  5.   

    提交页面前一个action saveToken(request);
    提交页面 <input type="hidden" name="org.apache.struts.taglib.html.TOKEN" 
    value="<%=session.getAttribute("org.apache.struts.action.TOKEN")%>"/>
    处理提交的action if(isTokenValid(request,true)){
    //commonDataBean.executeUpdate(sql);//处理执行sql语句代码
    resetToken(request);
    }else{
    saveToken(request);
    }
      

  6.   

    input.jsp
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 
    <%@ page contentType="text/html; charset=utf-8" %> 
    <html:html> 
    <head><title>Test</title></head> 
    <body> 
    <html:form action="/testAction.do" method="post"> 
    <br> 
    <html:text property="userName"/> 
    <br> 
    <html:text property="password"/> 
    <br> 
    <html:submit property="submit" value="Submit"/><br> 
    </html:form> 
    </body> 
    </html:html> 
    ----------------------------------------------------------------------------
    testAction.javapackage test; 
    import java.lang.reflect.InvocationTargetException;import org.apache.struts.action.ActionMapping; 
    import org.apache.struts.action.ActionForm; 
    import javax.servlet.http.HttpServletRequest; 
    import javax.servlet.http.HttpServletResponse; 
    import org.apache.struts.action.ActionForward; 
    import org.apache.struts.action.Action; 
    import org.apache.commons.beanutils.PropertyUtils;
    import org.apache.commons.el.Logger;
    import org.apache.commons.logging.*;;public class TestAction extends Action{ 
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
    HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { 
    Log log = LogFactory.getFactory().getInstance(
    this.getClass().getName());
    String userName = (String) PropertyUtils.getSimpleProperty(form,"userName");
    String password = (String) PropertyUtils.getSimpleProperty(form,"password");
    if (userName == null) { 
    saveToken(request); 
    return mapping.getInputForward(); 

    if (!isTokenValid(request)) { 
    saveToken(request); 
    System.out.println("不能重复提交!"); 
    return mapping.getInputForward(); 

    System.out.println("添加成功!");
    resetToken(request); 
    return mapping.findForward("success");
    }

      

  7.   

    上面的例子中并没有在jsp页面里使用隐藏什么变量,都可以的,我测试过了 ,重复提交就会有错误
      

  8.   

    认真看了我写的内容的意思了吗?<input type="hidden" name="org.apache.struts.taglib.html.TOKEN" 
    value="<%=session.getAttribute("org.apache.struts.action.TOKEN")%>"/>
    把这句原封不动的加到页面的from中
      

  9.   

    你用<html:form>是不需要自己写的,他会自己将<input   type= "hidden "   name= "org.apache.struts.taglib.html.TOKEN "   
    value= " <%=session.getAttribute( "org.apache.struts.action.TOKEN ")%> "/> 写入html,不信你可以自己看下源文件,
    问题是Struts的令牌其实是有问题的,多次提交他控制不了,
    处理提交的action if(isTokenValid(request,true)){ 
    //commonDataBean.executeUpdate(sql);//处理执行sql语句代码 
    resetToken(request); 
    }else{ 
    saveToken(request); 
    }
    这个写法是不对的,现在都在抄来抄去,根本都没自己去试
      

  10.   


    12楼的说的没错。
    第一次重复提交是被阻止了,阻止后saveToken();这时候页面不又有token了嘛,再一次点提交,这时候,真的就重复提交了。所以在isTokenValid(request)为假后不能saveToken();
      

  11.   

    确实不用管显示页面,struts会自己处理的,我的试过了,可以
      

  12.   

    我今天为了防止重复提交应用了saveToken(request),结果一直无法正常使用,只提交一次信息的时候也提示不能重复提交,
    具体情况如下:
    项目是ssh结构,一个模块的跳转和提交在一个action的不同方法中,
    link.do?method=postPo是进入提交页面,
    link.do?method=editPo是提交信息,
    在进入提交页面的方法中应用了saveToken(request);
    saveToken(request);在提交方法中做判断,如果重复提交输出错误信息
    if(!isTokenValid(request,true)){
    System.out.println("//////////////////////");
    ActionMessages error = new ActionMessages();
    saveErrors(request, error);
    return new ActionForward("/link.do?method=postPo");
    }
    else{
    //省略保存表单信息代码
    resetToken(request);
    }
    结果一直进入到"提示重复提交的分支中",这是为什么