views:

25

answers:

1

I have to display dialog box from servlet but without opening new window.

Below is code

PrintWriter printWriter =response.getWriter();
 String s ="<HTML><HEAD><TITLE>JavaScript Example</TITLE>"+
"<SCRIPT LANGUAGE=JavaScript>"+
 "alert('File Uploaded');"+
 "</SCRIPT>"+
   "</HEAD>"+
  "</HTML>";

printWriter.print(s);

This code open dialog in new window but I want dialog in current window.

A: 

It's hard to understand your problem. The posted code isn't opening a new window at all, it's just displaying an alert dialog. If you mean to say that it is opening a new window and then displaying the alert, then the problem rather lies in the calling code. Maybe you have a target="_blank" in the link or the form which is calling the servlet?


That said, generating view code in a servlet isn't always the best practice. JSP should be used for that.

BalusC