aspose file tools*
The moose likes JSP and the fly likes getting the user's system clipboard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "getting the user Watch "getting the user New topic
Author

getting the user's system clipboard

Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
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?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

What is the "user's buffer"?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
I'm quite possibly using the wrong terminology. I mean the clipboard, where the copied text is stored.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

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

Joined: Dec 18, 2008
Posts: 69
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

Applets execute in the browser; JSPs execute on the server.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

So where is the hidden text, and where is it you want to copy it to, and for what purpose?
Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

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 ... ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting the user's system clipboard