开发者

How to perform two actions on only one single click button in JSP?

开发者 https://www.devze.com 2023-02-24 08:51 出处:网络
I have created a JSP page with one browse button to upload a file and a submit button. I want to give auto-reply when user click on the submit butt开发者_运维问答on and the uploaded file must get save

I have created a JSP page with one browse button to upload a file and a submit button. I want to give auto-reply when user click on the submit butt开发者_运维问答on and the uploaded file must get saved at the same moment. In other words, I want to perform two actions at the same time on only one button click. How can I achieve this?


Just submit the form to a servlet.

<form action="uploadServlet" method="post" enctype="multipart/form-data">

In a servlet you've the freedom to hook some Java code on specific HTTP methods. You can just put code which processes the uploaded file, sets the message you want to display and finally forward the request to JSP to display the result. E.g. the following in the servlet's doPost() method:

processUploadedFile(request);
request.setAttribute("message", "Some message you want to display to user");
request.getRequestDispatcher("/WEB-INF/uploadResult.jsp").forward(request, response);

And finally in /WEB-INF/uploadResult.jsp file display the message as follows:

<p>Message: ${message}</p>


you can use post back form submit technique.

0

精彩评论

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