简体   繁体   中英

javascript dialogbox without opening page

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.

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.

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