Reputation: 183
I am submitting a form for file upload to a servlet but I don't know how to send a success event back to Javascript. I need to call a function after the servlet is successfully executed.
Upvotes: 1
Views: 1475
Reputation: 1109635
Just let the Servlet set a variable in request scope and let JSP generate the JavaScript code accordingly.
Servlet:
boolean success = true; // or false.
request.setAttribute("success", success);
request.getRequestDispatcher("/WEB-INF/result.jsp").forward(request, response);
JSP:
<script>var success = ${success};</script>
It will end up in webbrowser like
<script>var success = true;</script>
You know how to continue with this JavaScript, right? if (success) {} else {}
and so on :)
Upvotes: 1