Struts 里面有一个检查重复提交的机制:
具体可以参看 Struts-example 里面的相关程序:
in EditRegistrationAction:
// Set a transactional control token to prevent double posting
saveToken(request);
in SaveRegistrationAction 里面:
if (!isTokenValid(request)) {
    // 处理错误
}
resetToken(request);看着例子照着做就行了。

解决方案 »

  1.   

    structs  我看了它的原码,我觉得它不能解决重复提交的问题,它是在jsp自动把sessionID放在一个hidden中,这样,每个页面的hidden都是一样的,如何检测是否是新的提交还是以前的提交呢?
    所以我扩展structs,在它的formtag中,加入一个hidden变量requestID,value是一个随机数,当接到一个请求后,先对比以前的请求,如果一样,就不处理,否则,才继续进行.
      

  2.   

    in SaveRegistrationAction 里面:
    if (!isTokenValid(request)) {
        // 处理错误
    }
    resetToken(request); // 这一句很重要如果你第二次刷新在 isTokenValid(request) 就会发现错误。
      

  3.   

    从jguru.com上看到的,或许对你有用:
    Topic Monitoring  Notification  
    Struts Topic filtering: show [hide]
    This thread: off [monitor] Forum topic: off [daily] [weekly]
    This thread: off [notify] 
     Turn off caching off form data in struts?
    Topic: Struts 
    Brian Donahue, Aug 13, 2002  [replies:2]
    I'm still getting the hang of this stuff... but why do my forms in Struts seem to cache all the entered data? For example, if a user fills out a form, submits, then goes through other parts of my app, and later returns to repeat this process anew (e.g. for a second process) the data from the first process still appears in what I had assumed would be a blank form? I added 
    <controller nocache="true"/>to my config.xml but that didn't seem to have any effect. What am I missing here? I should note that this data persists even after shutting down my app server and browser and restarting...Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0
     
        Re: Turn off caching off form data in struts?
    Topic: Struts 
    Roeland Lengers, Aug 13, 2002  [replies:1]
    The normal answer would be: you store your FormBean in session (or application)-scope, and you don't throw it away when you're done with it. The next time you view the form, the struts controller will prepopulate the form with the data it already has in the session, so you would see the same data again.
    Unfortunately this answer does not apply since the data persists after shutting down you app server and browser. So, I can only try to help you pinpoint what it could be.
    Have you: 
    Shut down every browser on your system before trying again? 
    Shut down the appserver completely and then made sure there was no process running anymore (when using shutdown.sh with Tomcat, it sometimes doesn't do that, and I have to hard-kill it)? 
    Shut down the app-server completely and then tried to determine where it might have stored the data that you enetered previously? So, do a "greP' on your filesystem, or could it be stored in your database. 
    Checked that you did not supply "value" attributes for your form fields to inidcate default values? 
    That's what I could think of so far. Please let this forum know when you do find an answer.Hope this helps. Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0
     
        
      Re[2]: Turn off caching off form data in struts?
    Topic: Struts 
    Brian Donahue, Aug 13, 2002
    *BLUSH* Yeah, shortly after I posted this message I saw that several of our actions had been set to session scope, which should have been set to request scope, and that cleared it up. Silly cut and paste error. Thank you so much for the help!
     
    顺便把我的问题重发一遍:主  题:  struts中文问题请教 
    作  者:  teddy_huang ()  
    等  级:    
    信 誉 值:  100 
    所属论坛:  Java 
    问题点数:  50 
    回复次数:  2 
    发表时间:  2002-08-15 10:41:44 
       
     
       
    从jsp页面插入的中文在数据库中显示的是乱马,就是??,经过编码处理(转成gb2312)以后,数据库显示的还是??,但是在页面上可以正确显示,但是又出现了新的问题,页面上从resource由<bean:message>得到的中文又成了乱马,请问大虾现在该怎么办?
    我在web.xml中已经设置了
        <init-param>
          <param-name>content</param-name>
          <param-value>gb2312</param-value>
        </init-param>
    jsp页面上也设置了
    <%@ page contentType = "text/html; charset=gb2312" %>我用的是Tomcat4,数据库Oracle  
      

  4.   

    欢迎大家来讨论forward和redirect!
    还有那两位曾经回答过这个问题(重发之前)朋友来说声,好给分。