当前位置:
代码迷
>>
Web前端
>> Applet在web页面打开远程桌眼前端测试代码【备忘】
详细解决方案
Applet在web页面打开远程桌眼前端测试代码【备忘】
热度:
150
发布时间:
2012-08-15 16:57:17.0
Applet在web页面打开远程桌面前端测试代码【备忘】
曾经用Applet在web页面打开远程桌面的前端测试代码,后台代码无法公开,仅作备忘。
RdpApplet.java:
package com.elusiva.rdp.applet; import java.applet.Applet; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics; import java.awt.TextArea; import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import com.elusiva.rdp.Common; import com.elusiva.rdp.OrderException; import com.elusiva.rdp.RdesktopException; import com.elusiva.rdp.RdesktopSwing; public class RdpApplet extends Applet { private final String rdpShellPath = "C:\\Program Files\\XXX\\Open Virtual Desktop\\rdpshell.exe"; private RdpThread_2 rThread = null; private String[] argArray = null; private List<String> argList = new ArrayList<String>(); TextArea aTextArea = null; PrintStream aPrintStream = null; public void paint(Graphics g){ g.setColor(new Color(0xFFFFFF)); g.fillRect(0,0,g.getClipBounds().width,g.getClipBounds().height); g.setColor(new Color(0x000000)); int width = g.getFontMetrics().stringWidth("Launching isoft IVAPP Everywhere session..."); int x = (int) (g.getClipBounds().getWidth() / 2) - (width/2); int y = (int) (g.getClipBounds().getHeight() / 2); if(!redirectOutput) g.drawString("Launching isoft IVAPP Everywhere session...", x, y); width = g.getFontMetrics().stringWidth("Connect to Server..."); x = (int) (g.getClipBounds().getWidth() / 2) - (width/2); y = (int) (g.getClipBounds().getHeight() / 2) + 20; if(!redirectOutput) g.drawString("Connect to Server...", x, y); } boolean redirectOutput = false; public void init(){ redirectOutput = isSet("redirectOutput"); if(redirectOutput){ aPrintStream = new PrintStream( new FilteredStream(new ByteArrayOutputStream() ) ); System.setOut(aPrintStream); System.setErr(aPrintStream); aTextArea = new TextArea(); setLayout(new BorderLayout()); add("Center" , aTextArea); } initArgArray(); //getargArray(); } public void initArgArray() { String url = this.getParameter("url"); System.out.println("url=" + url); Map<String, String> params = null; params = RequestServer.doRequest(url); // 获取用户账号参数 argList.add("-u"); argList.add("31" + params.get("loginName")); // 获取用户密码参数 argList.add("-p"); argList.add(params.get("loginPassword")); argList.add("-fsmc"); //获取应用程序path argList.add("-s"); argList.add(rdpShellPath+" "+params.get("appExePath")); //获取IP参数 argList.add(params.get("ip")); argArray = new String[argList.size()]; Object[] objList = argList.toArray(); int j = 0; for (Object o : objList) { argArray[j++] = o.toString(); System.out.print(o.toString()); } } public void start(){ Common.underApplet = true; rThread = new RdpThread_2(argArray, this.getParameter("redirect_on_exit"), this); rThread.start(); } public void stop(){ rThread = null; notify(); } private boolean isSet(String parameter){ String s = this.getParameter(parameter); if(s != null){ if(s.equalsIgnoreCase("yes")) return true; } return false; } class FilteredStream extends FilterOutputStream { public FilteredStream(OutputStream aStream) { super(aStream); } public void write(byte b[]) throws IOException { String aString = new String(b); aTextArea.append(aString); } public void write(byte b[], int off, int len) throws IOException { String aString = new String(b , off , len); aTextArea.append(aString); } } } class RdpThread extends Thread{ String[] args; String redirect = null; Applet parentApplet = null; public RdpThread(String[] args, String redirect, Applet a){ parentApplet = a; this.args = args; this.redirect = redirect; } public void run(){ this.setPriority(Thread.MAX_PRIORITY); try { RdesktopSwing.main(args); if(redirect != null){ URL u = new URL(redirect); parentApplet.getAppletContext().showDocument(u); } } catch (OrderException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RdesktopException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block System.err.println(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } Common.underApplet = false; } }
RequestServer.java:
package com.elusiva.rdp.applet; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Iterator; import java.util.Map; public class RequestServer { public static void main(String[] args) throws IOException { String requestURL = "http://192.168.210.201/sm/webservices/server_random.php?type=windows&sid=1293712837Q5yTs"; doRequest(requestURL); } public static Map<String,String> doRequest(String requestURL) { Map<String,String> params = null; try { //创建URL URL url = new URL(requestURL); //打开URL连接 URLConnection connection = url.openConnection(); /* * 然后把连接设为输出模式。URLConnection通常作为输入来使用,比如下载一个Web页。 * 通过把URLConnection设为输出,可以把数据向某个Web页传送,如下: */ connection.setDoOutput(true); // 一旦发送成功,用以下方法就可以得到服务器的回应: InputStream is = connection.getInputStream(); //解析XML获取参数 params = XMLReader.ParseXML(is); } catch (MalformedURLException e) { System.out.println("创建URL失败!"); } catch(IOException e){ System.out.println("打开连接失败!"); } return params; } }
XMLReader.java:
package com.elusiva.rdp.applet; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class XMLReader { private final static Map<String,String> params = new HashMap<String,String>(); public static Map<String,String> ParseXML(InputStream is) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(is); //以去掉XML文档中作为格式化内容的空白 doc.normalize(); NodeList links = doc.getElementsByTagName("server"); Element link = (Element) links.item(0); //将参数放到map中 String code = link.getElementsByTagName("code").item(0).getFirstChild().getNodeValue(); if("0".equals(code)){ params.put("ip", link.getElementsByTagName("ip").item(0) .getFirstChild().getNodeValue()); params.put("loginName", link.getElementsByTagName("loginName").item(0) .getFirstChild().getNodeValue()); params.put("loginPassword", link.getElementsByTagName("loginPassword").item(0) .getFirstChild().getNodeValue()); params.put("appExePath", link.getElementsByTagName("appExePath").item(0) .getFirstChild().getNodeValue()); } } catch (Exception e) { System.err.println(e.getMessage()); } return params; } }
查看全文
相关解决方案
Java Applet 的路劲该如何指定啊
Applet 文件上传进度条有关问题
急js调用java applet 有关问题,多谢!
java swing or applet?解决方法
关于java applet 图片处理的有关问题,请高手帮下忙
Java applet 文件下传
java applet 上拉列表沒有上拉選項
? asp.net的web页面中怎么调用编写好的java applet
C写的CGI中嵌入JAVA Applet,没法显示?
Applet QuoteWinnerLite destroyed解决方法
Applet QuoteWinnerLite destroyed解决办法
applet,servlet读音
java applet "启动:未初始化小程序。”
JAVA设计实现一个个人电话簿。(Swing/Applet, JDBC)
Applet的子类初始化时报java.awt.HeadlessEception() java.awt.Applet.init ...
Applet JSP
applet
一个Clock程序(Applet & Application)
applet 我的第一个 不会
applet 怎么学?
请问如何调用一个extends java.applet.Applet的类
[求助]无法显示 applet.html
applet 问题
[求助]Java Applet
applet 请教
Applet 程序怎样在网页中运行!
怎样编Java小程序(Java Applet)
java小程序(Java Applet) 上个贴发的解决了一点 但是还得修改 高手帮忙
关于JAVA Applet 背景图片问题
如何让 applet 跨框架和浏览器窗口彼此通信