• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to show a pop up window from a servlet

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic