• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Taking screenshot of JSP page Using java

 
Jai babu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want to take the screenshot of Jsp page in the browser. I had googled a lot. Everyone is pointing to java.awt.Robot functionality. It is great. But what i need is i want the screenshot of the full web page which is also inside the scrollable area of the browser window. Moreover i want only the webpage content not the status bar and other tabs and menus on the browser. I had used the following code.

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Robot robot = new Robot();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width-15, screenSize.height);
BufferedImage image = robot.createScreenCapture(rectangle);
ImageIO.write(image, "gif", new File("c:\\Temp\\mmgg.jpg"));

Is there a way to take the screen shot of the full JSP webpage that is viewing in the browser.(Along the content inside the scrollable window). Some tutorial points to Selenium function browser.captureEntirePageScreenshot("C:\screenshot.png","");. But not able to implement it in my JSP page which i run through tomcat and spring framework.

Thanks
Jai
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to embed this code in a JSP page? If so, be aware that it won't work once you access the page from a machine other than the one the server runs on.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a picture of how the JSP looks in the browser on the client machine, you'll have to do something in the browser on the client machine. That would exclude Java code in the JSP, since that would run in the server. So probably you're looking at some kind of Javascript function to do that.
 
Jai babu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Thanks for your replies. Yes i agree both points. But what i need is, is it possible to take the screen shot of the full webpage displayed in the browser along with the content inside the scrollable area by using java.awt.Robot. (It should be single screenshot). If yes can anyone show me the code todo that. Otherwise as Paul Calpham said is there any javascript that take the screen shot of the webpage content inside the browser area. Please, make your valuable points to me.

Thanks
Jai
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this really has nothing to do with JSP, it's been moved to a more appropriate location.
 
Jai babu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My question is how to take screenshot of full webpage in the browser by using java.awt.Robot. I hope it comes under the topic Java/JSP.

Thanks
Jai
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're aware that JSPs run on the server, not in the browser, right? So if you want to use Java classes in the browser you'll need to use applets or JNLP/Java Web Start.

But what i need is i want the screenshot of the full web page which is also inside the scrollable area of the browser window. Moreover i want only the webpage content not the status bar and other tabs and menus on the browser.

I don't think it's possible to achieve either of these using the Robots class.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You started out saying "I want..." but everybody has been assuming that you want some program to do that. If we were to interpret you literally the answer would be "Press Alt-PrtSc" and edit the result with Microsoft Paint". At any rate you haven't said anything about the context or about the actual requirement.

So here's another solution: download the JDIC code. Display your JSP in a WebBrowser component in a Java program, then have something in that Java program capture the contents of that component.

(Warning: JDIC looks like cool stuff but it's hard to configure and doesn't come with examples and was apparently abandoned about a year ago. Not for people who can't figure things out for themselves.)
 
Jai babu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ulf Dittmer,

Thanks for your reply. I got the problem what was it. Even if i go for Applet and embed it in he JSP page i hope it will take the screenshot of the viewable browser part but not the content inside scrollable area. Moreover it will take the desktop screenshot not the browser window only. Hope there is no other solution of taking client side screen shot of the web page in the browser with Java. If there is something todo with java please make a note of it.

Thanks
Jai
 
Jai babu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Paul Clapham,

Its my mistake that i didn't make my problem clear. Sorry for that. I will go ahead with JDIC code. If any problem i will come back again. Please give your valuable points.

Thanks
Jai
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jai babu wrote:Its my mistake that i didn't make my problem clear.


The main problem was that you didn't say "I want to be able to take a screenshot of a JSP in a browser" or "I want a JSP in a browser to be able to take a screenshot of itself". Those are different things. Your original post sounded like the second statement, which to me sounds like a peculiar requirement. This led me to suspect that the original requirement was actually the first statement, but that you were confused and trying to implement the second statement.

So it might be good if you paused and tried to clarify your requirement in your own mind.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic