views:

19

answers:

1

HI All ,

I am submitting a form for file upload to a servlet but i dont know how to send a success event back to java script , actually i need to call a function after the servlet is successfully executed . Please help me to find out possible approach .

A: 

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 :)

See also:

BalusC
I dont want to change the page by using requestDispatcher
Vinay
It isn't changing the page. It is just **displaying** the JSP page associated with the request. A redirect is changing the request. I don't see where this aversion is coming from. Your *actual* problem lies now somewhere else. If you elaborate *why* you don't want to use the dispatcher, then we can suggest different approaches.
BalusC