Hello All, I have an email application, which is hosted inside a jsp page, which is displayed to the users to send any error report to the developer from the application itself. Everything works, since i have a textarea inside the jsp where the users type, the text message. I wanted to know is there a way if i can get the screen shot of the user desktop windows in that email message which is being prepared. So basically if the user presses printscreen, is there a way i can get that screencapture in the text area or any other HTML object so that i can send that message out from my jsp code.
(1) Platform dependence. There's simply no standard, cross-platform screenshot API you can invoke. Someone may have written a portable library of some kind, but it's unlikely to be installed on everyone's machine. Which brings us to...
Now, if this is an Intranet application where all the desktops are Windows, and you can install a java.policy file on each machine, then the path is clear -- it's just a Small Matter of Program. But for the whole problem in its terrible generality, the problems are likely to be insurrmountable.
Yeah, I appreciate the problems when the platform is not standardized.
I can reasonably generalize for the purposes of my application that it will be Windows 2000/Windows XP (more so the latter) and the browser will be Internet Explorer 6.0.
I gather from a preliminary look on the internet that VBScript accomplishes the opening of the default mail client best (It will be Outlook 2003 for my purposes). I don't need to configure server-related credentials. All I want to do is open Outlook with a pre-meditated addressee, subject and the attachment (the same way a mailto: link functions, but it doesn't support attachments unfortunately)
I have successfully implemented screen capturing in Java/JSP. It is the sending of the mail with the screen caps as attachments that is the stumbling block now. Appreciate any pointers on this one. [ June 17, 2008: Message edited by: Sridhar Venkataraman ]
Hi Sridhar, Since I started this thread, let me just add what i come up with. I have implemented, the screen capturing using the standard java api, which created a screenshot.jpg file. Now for me since this location will be constant every time, so when the user click the send email button, this triggers the fileupload action in the background of this screenshot.jpg file on the server, as the mail code is present in jsp,with the help of some flags i detect if the file is uploaded if yes, i just send it from the java mail as attachment. basically you need to get some user action to trigger this email send.
Are you storing the screenshot on the server or on a location on the user's workstation?
For me, I am throwing up a Save dialog asking the user to save it. As soon as they do that, I need to trigger off an e-mail with that file as an attachment.
The problem is that the Java Mail API is cumbersome to use with Outlook. VBScript works superbly, but I can't make a link between the capturing of the screenshot (which is a JAR file implementation...it triggers when the "send e-mail" action is performed by the user) and the running of the VBScript to attach this to a mail message in the JSP application.
Hi, So originally the file is stored on the user workstation, but once the user click send email button, i post that file to the servlet, where its written in a temp file and sent out as an email attachment, and i delete once email is sent in the same code. And for the screen capture i just use on java class to achieve it, wonder what your jar implementation of screen capture provides ??
I really wanna hear about your approach, just to know the alternatives,
The JAR provides a screen capture, but I am unable to fire up my default mail client (which is Outlook) using the Java Mail API (it is quite cumbersome to define SMTP settings and the like..).
I have VBScript which can open up a blank message with initial parameters (To, CC, BCC, Message Body) etc. and an attachment.
The problem is that I need to execute the two together when the user clicks a link on my JSP page.
As far as I know, Java cannot interact with VBScript. I tried registering the Java class as a COM object and then using the object inside VBScript code, but I learnt that Microsoft support for the MSJVM has been ended as of 31 December 2007.
Another way I can do this is to create a batch file on the server. The batch file will first execute the java program that captures a screenshot and places it in a predetermined location on the user's computer. It will then invoke the VBScript to attach this screenshot and open up a mail message like the one talked about above.
Now the problem is figuring out how to run a batch file when a user clicks on a link. Any pointers on that? [ June 18, 2008: Message edited by: Sridhar Venkataraman ]
Hmm, So, i dont know how UI-tically this will be feasible for you. But to trigger your two actions you may need two user intervention. So in my jsp, i have this button which says report problem, when the user clicks it, i trigger the screen shot capturing, and save the file in the desired location. Once, the user fills in the text area for the email, and clicks the send email button on this new jsp, i upload that screenshot(if it exists) and the text area data to the server, for sending out the mail.
You can do something like a onload of jsp, for triggering of the screen capture,
P.S. I use an applet to get the control of user system or the screen capturing.
Your solution is good, albeit fairly complex. My requirement is for an easily maintanable solution, though it may be scrappy.
I have made a few modifications to the architecture such that I don't need to run a batch file directly when the user clicks a link, but rather invoke a Java class which can run a batch file. But this too is posing some problems for me.
And that's because I attempted to add additional functionality to the java applet. Currently, I am hardcoding the location where the screenshot is to be stored and then picking it up to attach to a mail message based on the same location.
There was a new requirement to throw up a save dialog within the applet after the screenshot is taken so that the user can choose where to save the file, and then attach the file to the mail message from there.
So I implemented the same using the Java Swing API. In the code, I throw a save dialog where the user specifies the name of the file.
My java console shows the following stack trace when I fire this whole process up:
I am surprised that I don't have read permission although I did have write permission as implemented earlier. How do I give my applet read permission to the user's file system? It is self-signed and all the code which accesses the user's file system is implemented as privileged code.
Your assistance is much appreciated.
I managed to bypass the security restriction (It surprised me because I did not explicity do anything in the code which dealt with security).