简体   繁体   中英

Passing the response of servlet response back to previous jsp page

How can we pass the message eg "File uploaded successfully" to a calling/previous jsp page(say upload.jsp). The jsp page is fetching attribute of the session and checks the department from which user has logged in. It the acknowledges user with name of department . When the user upload files and the servlet is called in form action .The servlet then checks department name and insert data in a database and should show the message "File uploaded successfully" to the user on same upload.jsp page. When iam passing the page in request dispatcher null pointer exception occurs. But the same code works fine when i pass this message to a new jsp page. I have tried both include and forward methods. I want the servlet to redirect to the same jsp page ("/upload.jsp"). Please help me!!

The easiest way may be to submit the form via ajax.
Example: How to submit multipart formdata using jquery

The other option is to re-reneder the upload page that submitted the form. If this is what you are attempting, and you are getting a null pointer exception, it sounds like you are missing required data. You may want to do a 'post redirect get' strategy. it's best not to just return to the user after a form post because if the user refreshes the browser will likely attempt the post again. Since you are using spring, use a spring redirect. You have to make sure your message is added to the RedirectAttributes though. examples

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM