JAVA的web截图功能实现
2012-11-22 13:37
561 查看
需求:在网页上点击按钮,打开截图程序。截图后,弹出页面,填写相关文字性的内容,将所截到的图片以邮件形式发送出去。
不让采购小公司的截图插件,就只能自己搞了。
1、开发客户端截图软件(基于JPanel),接收参数。将截到的图片上传到参数指定的服务器上,并使用本地IE打开邮件发送的页面。
2、在页面中嵌入Applet程序,点击按钮触发程序中的事件,从而打开截图程序。
关键代码:
1、截图程序(代码太多了,没时间搞,先只贴main)
2、Applet
3、页面
4、注册(获取applet操作本地文件的权限)
keytool -genkey -keystore q.store -alias q
keytool -export -keystore q.store -alias q -file q.cert
jarsigner -keystore q.store openExe.jar q
效果:
点击交办,则使用javamail发送邮件。
不足:只适用于IE;第一次使用程序运行速度较慢;胖客户端,需要用户安装程序。
不让采购小公司的截图插件,就只能自己搞了。
1、开发客户端截图软件(基于JPanel),接收参数。将截到的图片上传到参数指定的服务器上,并使用本地IE打开邮件发送的页面。
2、在页面中嵌入Applet程序,点击按钮触发程序中的事件,从而打开截图程序。
关键代码:
1、截图程序(代码太多了,没时间搞,先只贴main)
/* * 参数:截图后跳转的URL */ public static void main(String[] args) { TestFrame tf=new TestFrame(); tf.jtbtnClick(); tf.setAlwaysOnTop(true); //顶层显示 boolean isCaptured = tf.saveImg(); //是否截图 if(isCaptured){ //上传图片 try { ImageUpload.uploadImage(tf,SCUtil.processUrl(args[0])); } catch (Exception ee) { ee.printStackTrace(); } while(!tf.getUploaded()){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } //延迟半秒打开网页 try { Thread.sleep(500); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //打开本地网页 try { Runtime.getRuntime().exec( "\""+System.getenv("ProgramFiles")+"\\Internet Explorer\\IEXPLORE.EXE\" "+args[0] ); //C:\\Program Files\\ScreenShotClient\\temp\\run.html } catch (IOException e) { e.printStackTrace(); System.exit(0); } } tf.dispose(); System.exit(0); }
2、Applet
import java.applet.Applet; import java.security.Permission; import javax.swing.SwingUtilities; public class OpenExeApplet extends Applet { private class DefaultSecurityManager extends SecurityManager{ @Override public void checkPermission(Permission perm) { } @Override public void checkPermission(Permission perm, Object context) { } } public void init() { System.setSecurityManager(new DefaultSecurityManager()); } public String openExe(){ String path = getParameter("path"); if(null == path){ path = getParameter("src"); } try{ Runtime rt = Runtime.getRuntime(); String[] cmd = path.split("|&@"); rt.exec(cmd); }catch(Exception e){ e.printStackTrace(); return e.getMessage(); } return "success"; }
3、页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = "C:/Program Files/ScreenShotClient/screen.exe|&@http://192.25.102.140:8080/BI"; %> <html> <head> <title>打开截图软件</title> <script type="text/javascript"> function openApp(){ var str = document.applets[0].openExe(); alert(str); } </script> </head> <body> <input type="button" value="open" onclick="openApp()" /> <object classid="clsid:CAFEEFAC-0015-0000-0007-ABCDEFFEDCBA" id="qApplet" name="qApplet" style="top:0;left:0;position:absolute;" width="1" height="1" codebase="http://192.25.102.128:8080/LocalOpen/download/jre-6u17-windows-i586.exe" > <param name="java_code" value="OpenExeApplet.class"> <param name="java_archive" value="/LocalOpen/download/openExe.jar"> <param name="type" value="application/x-java-applet;version=1.6"> <param name="scriptable" value="true"> <PARAM name="MAYSCRIPT" value="true"> <param name="boxbgcolor" value="#ffffff"> <param name="src" value="<%=path %>"> <embed type="application/x-java-applet;version=1.6" id="qApplet" name="qApplet" width="1" height="1" pluginspage="http://java.sun.com/products/plugin/" java_code="OpenExeApplet.class" java_archive="/LocalOpen/download/openExe.jar" src="<%=path %>" scriptable="true" MAYSCRIPT="true"> </embed> </object> </body> </html>
4、注册(获取applet操作本地文件的权限)
keytool -genkey -keystore q.store -alias q
keytool -export -keystore q.store -alias q -file q.cert
jarsigner -keystore q.store openExe.jar q
效果:
点击交办,则使用javamail发送邮件。
不足:只适用于IE;第一次使用程序运行速度较慢;胖客户端,需要用户安装程序。
相关文章推荐
- Selenium webdriver实现截图功能
- 【Java.Web】Session —— Session的持久化(容器实现此功能)
- java-FFmpeg(一) 实现视频的转码和截图功能
- 关于JavaWeb如何实现用户注册 后台即时提醒(类似站内信功能)
- JAVA应用XFire框架来实现WebServie的大文件传输功能之一(下载)
- 【Java.Web】Session —— Session的持久化(容器实现此功能)
- Selenium Webdriver实现截图功能的示例
- JavaWeb登陆功能实现代码
- Jcrop Java实现截图的功能
- javaweb基本的分页功能实现
- java自带webservice功能实现Javax.jws.WebService--JAX-WS
- 22、关于Drools Web版本与java实现自动扫描功能
- 【从零写javaweb框架】(五)实现依赖注入功能
- java web开发之servlet图形验证码功能的实现
- java web开发:servlet中图形验证码功能的实现
- JAVA功能代码《6》----用Java实现屏幕截图
- Java web 注册登录功能实现简介
- Javaweb中结合mysql数据库实现分页功能
- java web中实现同一帐号同一时间只能一个地点登陆(类似QQ登录的功能)
- JAVA功能代码《6》----用Java实现屏幕截图