• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

JOptionPane No X11 DISPLAY error  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to popup one message using JOptionPane. I am getting following error:



How can i fix this?
 
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By running the program from a windowed environment, like GNOME, KDE, Enlightenment, etc. Judging from that exception, you are running the program on a command line without any windowing system running, probably a server. So where are you going to display the JOptionPane?

If you get a HeadlessException you can sometimes prevent it by using the -Djava.awt.headless=true JVM property (which comes before the class name), but only if you don't really need the windowed environment. Which you do in this case.
 
Tarun Kumar Agrawal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have deployed my code on one machine. I am running this from another machine using url: http://machine-ip:8080. Everything is displaying properly except that JOptionPane Message.
 
Rob Spoor
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course that won't work. The servlet / JSP code runs on the server, not on the client. That means that the JOptionPane dialog will be shown on the server, and there's no graphical environment there (or else you wouldn't get this exception). You'll have to use JavaScript to show messages to the user.
 
Tarun Kumar Agrawal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i call Javascript function from java servlet?
 
Java Cowboy
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot. The servlet runs on the server, the JavaScript code in a HTML page runs on the client. The servlet sends back data (often in the form of a HTML page), which can also contain JavaScript. You could make the servlet return a page with some script in it that is run when the browser loads the page.

A web application does not work in exactly the same way as a desktop application, where you can display a message box at any time. You have to be aware of the HTTP request-response cycle, and what code runs where (server or client) and when.
 
Rob Spoor
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to show a JavaScript dialog from a servlet is indeed by simply letting the generated HTML page contain code to show the dialog:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!