前提:成功安装guacd服务后。需要把guacd监听的IP改为自己的内网或者公网IP,而不是127.0.0.1。开放4822端口 以便外部访问
1.建立一个maven工程引入servlet,guacamole-common,guacamole-common-js 这三个依赖。
2.新建一个servlet(也可以用spring去实现)
3.html页面访问servlet
public class DummyGuacamoleTunnelServlet extends GuacamoleHTTPTunnelServlet {
@Override
protected GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException {
// guacd connection information
String hostname = "192.168.2.66";
int port = 4822;
GuacamoleClientInformation client= new GuacamoleClientInformation();
client.setOptimalScreenHeight(Integer.parseInt(request.getParameter("GUAC_HEIGHT")));
client.setOptimalScreenWidth(Integer.parseInt(request.getParameter("GUAC_WIDTH")));
client.setOptimalResolution(Integer.parseInt(request.getParameter("GUAC_DPI")));
GuacamoleConfiguration config = new GuacamoleConfiguration();
config.setProtocol("ssh");
config.setParameter("hostname", "192.168.2.8");
config.setParameter("port", "22");
config.setParameter("username", "你的主机用户名");
config.setParameter("password", "密码");
config.setParameter("color-scheme", "black-white");
config.setParameter("font-name", "SimSun");
config.setParameter("font-size", "12");
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
new InetGuacamoleSocket(hostname, port),
config,client
);
GuacamoleTunnel tunnel = new SimpleGuacamoleTunnel(socket);
return tunnel;
}