最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to clear the form after submitting the values? - Stack Overflow

programmeradmin3浏览0评论

I have a form with few filed. Once i submit the form the data is stored in database and i will return to the same page. Now, How to clear the fields in the form??

It is a struts based application. On submit it does some validations using java script then forwarded to the same page. Now, I must get a fresh page. I mean the fields must be cleared.

I have a form with few filed. Once i submit the form the data is stored in database and i will return to the same page. Now, How to clear the fields in the form??

It is a struts based application. On submit it does some validations using java script then forwarded to the same page. Now, I must get a fresh page. I mean the fields must be cleared.

Share Improve this question asked Mar 12, 2011 at 5:38 priyapriya 4,3678 gold badges24 silver badges15 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 2

You can override Struts' Action reset() method and after you used it in your action you can do form.reset(request, response); and do a forward. That way, your form is resetted.

Can't you just use the javascript reset() method on the form?

You can have 2 options use on load JavaScript form.reset() or you can clear your formclass fields before returning to your form ie define a reset method in your struts form class call this method before return.

you can clear the form with the reset method of your form.

You can use redirect method like this :

request.setStatus(request.SC_SEE_OTHER);
request.setHeader("Location",url);

Where SC_SEE_OTHER is the proper 303 code and "url" is the url of you current page this will reload your page so all your filed will be reset.

In my case i handle in java action class , you should clear the model or bean object in your java class before return Action.SUCCESS; example customerDetail.setId(""); customerDetail.setName("");

发布评论

评论列表(0)

  1. 暂无评论