开发者

How to clear the form after submitting the values?

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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜