当前位置: 技术问答>java相关
重发:struts 中的刷新问题
来源: 互联网 发布时间:2015-08-09
本文导语: 说明: 信誉分是找回来了,可是贴子只有重发了。请上次回答问题的两位网友再把你们的回复贴一下,让我好给分。大家也可以再来讨论一下这个问题: 当刷新显示结果的jsp页面时,又重新执行了一次请求,...
说明:
信誉分是找回来了,可是贴子只有重发了。请上次回答问题的两位网友再把你们的回复贴一下,让我好给分。大家也可以再来讨论一下这个问题:
当刷新显示结果的jsp页面时,又重新执行了一次请求,也就是Action又以第一次请求中输入的Form中的值又执行了一次。后来,朋友告诉了一个办法:通过在session中加一个参数来判断,这样一来刷新的问题是避免了,但是当第二次请求时,由于session中的值没有改变回来,结果还是当成了刷新,action中下面的操作没有执行到!
大家有没有碰到这样的问题?是怎么解决的?
附:
请求、响应过程是这样的:
form form
用户输入jsp页面——〉Action——〉显示的结果的jsp页面
我自己的解决方法是:
在struts-config.xml中的action属性forward中加上redirect="true".不过,这样一来,ActionForm就不能在显示结果的页面中用了。
大家有什么好的方法可以在这里再讨论一下!
信誉分是找回来了,可是贴子只有重发了。请上次回答问题的两位网友再把你们的回复贴一下,让我好给分。大家也可以再来讨论一下这个问题:
当刷新显示结果的jsp页面时,又重新执行了一次请求,也就是Action又以第一次请求中输入的Form中的值又执行了一次。后来,朋友告诉了一个办法:通过在session中加一个参数来判断,这样一来刷新的问题是避免了,但是当第二次请求时,由于session中的值没有改变回来,结果还是当成了刷新,action中下面的操作没有执行到!
大家有没有碰到这样的问题?是怎么解决的?
附:
请求、响应过程是这样的:
form form
用户输入jsp页面——〉Action——〉显示的结果的jsp页面
我自己的解决方法是:
在struts-config.xml中的action属性forward中加上redirect="true".不过,这样一来,ActionForm就不能在显示结果的页面中用了。
大家有什么好的方法可以在这里再讨论一下!
|
Struts 里面有一个检查重复提交的机制:
具体可以参看 Struts-example 里面的相关程序:
in EditRegistrationAction:
// Set a transactional control token to prevent double posting
saveToken(request);
in SaveRegistrationAction 里面:
if (!isTokenValid(request)) {
// 处理错误
}
resetToken(request);
看着例子照着做就行了。
具体可以参看 Struts-example 里面的相关程序:
in EditRegistrationAction:
// Set a transactional control token to prevent double posting
saveToken(request);
in SaveRegistrationAction 里面:
if (!isTokenValid(request)) {
// 处理错误
}
resetToken(request);
看着例子照着做就行了。
|
从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
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由得到的中文又成了乱马,请问大虾现在该怎么办?
我在web.xml中已经设置了
content
gb2312
jsp页面上也设置了
我用的是Tomcat4,数据库Oracle
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
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由得到的中文又成了乱马,请问大虾现在该怎么办?
我在web.xml中已经设置了
content
gb2312
jsp页面上也设置了
我用的是Tomcat4,数据库Oracle
|
structs 我看了它的原码,我觉得它不能解决重复提交的问题,它是在jsp自动把sessionID放在一个hidden中,这样,每个页面的hidden都是一样的,如何检测是否是新的提交还是以前的提交呢?
所以我扩展structs,在它的formtag中,加入一个hidden变量requestID,value是一个随机数,当接到一个请求后,先对比以前的请求,如果一样,就不处理,否则,才继续进行.
所以我扩展structs,在它的formtag中,加入一个hidden变量requestID,value是一个随机数,当接到一个请求后,先对比以前的请求,如果一样,就不处理,否则,才继续进行.