Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA servlets - open message popup

I want to user HttpServletResponse object to compose a response that will tell the browser client to open a popup with some message - how can i do that?

like image 657
Erik Sapir Avatar asked Dec 13 '22 18:12

Erik Sapir


1 Answers

Every Servlet response is basically an Http doc/snippet. So you could return a call to a javascript function that will be executed on the client side. The function can be passed in that Servlet response or it can be pre-included in the .js file.

just an example:

//servlet code
PrintWriter out = response.getWriter();  
response.setContentType("text/html");  
out.println("<script type=\"text/javascript\">");  
out.println("alert('deadbeef');");  
out.println("</script>");
like image 110
Vuk Avatar answered Dec 26 '22 16:12

Vuk