• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting the user's system clipboard

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to find an easy way that, when a user clicks on an SVG-generated image in a browser, the original text that was used to generate that SVG is copied into the user's buffer. The most general solution appears to be the window.prompt() Javascript method, but it requires two additional keystrokes on the part of the user to copy the text and to close the prompt window. Given that Java applets allow one to copy text into a system's buffer, I was wondering whether AJAX might provide a solution here; that is, upon clicking the image, start a Javascript method that uses AJAX to send the text to a JSP page that has a Java routine that copies the text into the System buffer. So I wrote such code, but I get a HeadlessException when I try to get the system's Clipboard. Here's the code that throws the exception:



I tried temporarily setting the system's headless property to false, but no joy:



So, my question is, is there any way to salvage this attempt, or am I completely barking up the wrong tree?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the "user's buffer"?
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm quite possibly using the wrong terminology. I mean the clipboard, where the copied text is stored.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, there's no such thing as a server-side clipboard, and you don't have access to the client system's clipboard (except in security-moronic IE), so whatever it is you are trying to accomplish is unlikely to involve a clipboard.

So what is it you actually are trying to accomplish?
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to copy hidden text on a Web page with a single click on a visible image.

I know that Java applets have access to the client system's clipboard, because I can use an applet's copy function to copy information and paste it into a different application. I'm trying to access this same ability through a JSP page. How do applets access the client system's clipboard?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Applets execute in the browser; JSPs execute on the server.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So where is the hidden text, and where is it you want to copy it to, and for what purpose?
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, my mistake was assuming that the JSP page executes on the client side.

The hidden text is XML that describes a chemical structure. I am displaying XML (SVG) that is the image of said chemical structure. Currently, I have the entire image XML surrounded by ..., calling this method:



where getOrigMol() returns the XML describing the structure. This procedure works, but it requires three actions from the user (click on image, copy highlighted text in popup, close popup) and produces an annoying popup. I thought I had discovered a way around the prohibition on Javascript accessing the client's clipboard. But my brilliant idea is no good after all. Story of my life.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Grossman wrote:Ah, my mistake was assuming that the JSP page executes on the client side.


I think you will find this article very helpful in understanding how JSP works.

where getOrigMol() returns the XML describing the structure. This procedure works, but it requires three actions from the user (click on image, copy highlighted text in popup, close popup) and produces an annoying popup. I thought I had discovered a way around the prohibition on Javascript accessing the client's clipboard. But my brilliant idea is no good after all. Story of my life.



If getOrigMol() (surely a more readable name is possible) returns an XML document, then you can use jQuery to find the info you want within it. If it's not an XML document, but just an XML string, then maybe a regex could work.

What you want to do with the info after you've gotten it is ... ?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic