Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to show a pop up window from a servlet

 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I want to present an error message using a pop up box (like a message box) instead of presenting an HTML page with error message on it. Can you please tell me how I can show a pop up box from a servlet?
Thanks
Suresh
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not remember exactly what context I had used but I got pop up box. I think I imported javax.swing.* package. Then I used JOptionPane.showMessageDialog. I had simple choice yes, NO button and it worked. I wanted to paste code for you but switching tomcat3.2 and tomcat4.0 back and forth they all are gone. Try that out, how does it react let us know?
BK
Originally posted by Suresh Kanagalingam:
Hello,
I want to present an error message using a pop up box (like a message box) instead of presenting an HTML page with error message on it. Can you please tell me how I can show a pop up box from a servlet?
Thanks
Suresh

 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
You can use a javascript alert like this:

Just put the script code it in after the body tag and the javascript will execute on page loading. (if you put it in head it would have to be called)
I'm using this myself in a JSP Form page that calls itself and alerts the error message text and if there are no errors it accesses a DB.
I found it neater than a separate page
Hope that helps,
------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Terence Doyle (edited October 04, 2001).]
 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bal,
I tested JOptionPane and it works fine if I use it in a standalone Java application. If I use it in a servlet, which is what I need, the browser takes for ever to respond and eventually times out.
Is it because JOptionPane.showMessageDialog is solely for applications and not for servlets?
I am using Websphere as the app server.
Note: The servlet finds the JOptionPane class from CLASSPATH properly.
Thanks
Suresh
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything showing up on a browser has to be put there by writing HTML to the request. Any JAVA GUI that a servlet generates can only show up WHERE THE SERVLET IS RUNNING! ON THE SERVER! NOT ON THE BROWSER!
 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William,
Any thoughts on how I can do this?
I tried using an applet. Applet shows up (using JOptionPane.showMessageDialog) but it does not respond to any mouse clicks when I press the ok button. Do you know why?
Thanks
Suresh
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As explaind previously by Bill Brogden, any GUI displayed by your servlet has to be HTML generated. Short of using JavaScript, I don't know any other way to do what you want to do. Unless you use an applet, of course.

Bosun
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Suresh:
I see best option for you is JAVASCRIPT. Is there any problem using java script in middle of your document? I thnik this is the beauty of JSP. USE JAVA CODE, JAVA BEAN, CUSTOM TAG, JAVA SCRIPT, AND, HTML WHEREEVER YOU NEED YOU FULFILL YOUR REQUIREMENTS. I am beginner here, SO do not take my word as final. Please listen what expert say. Keep posting good stuffs.
GOOD LUCK ON YOUR PROJECT. BK

Any thoughts on how I can do this?

 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone.
I got around by calling a JSP, which runs javascript, from the servlet using RequestDispatcher. It works cool.
Suresh
 
Mark Leong
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since we are talking a little about Javascript here, I wonder if somebody can help me with this problem:-
When a page is loaded, I added the following javascript to open as new window:-
newwindow = window.open("some.htm", "somenewwindow");
However before executing the statement, is it possible for me to check if "somenewwindow" is opened? I tried the following but it does not work as the window has not been created when the "if" statment is first executed.
if (somenewwindow == null){
//open the new window
} else {
//do not open
}
 
Bring out your dead! Or a tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!