我尝试从下面的教程中为 ssh 构建一个演示 guacamole 应用程序。
http://guac-dev.org/doc/gug/writing-you-own-guacamole-app.html
只要值是硬编码的,该应用程序就可以正常工作。但我需要从用户那里获取主机名/IP。为了实现这一点,我尝试在下面的代码中使用request.getParameter() :
package org.glyptodon.guacamole.net.example;
import javax.servlet.http.HttpServletRequest;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.GuacamoleSocket;
import org.glyptodon.guacamole.net.GuacamoleTunnel;
import org.glyptodon.guacamole.net.InetGuacamoleSocket;
import org.glyptodon.guacamole.net.SimpleGuacamoleTunnel;
import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
import org.glyptodon.guacamole.servlet.GuacamoleHTTPTunnelServlet;
public class TutorialGuacamoleTunnelServlet
extends GuacamoleHTTPTunnelServlet {
@Override
protected GuacamoleTunnel doConnect(HttpServletRequest request)
throws GuacamoleException {
// Create our configuration
String hostname = request.getParameter("hostname");
GuacamoleConfiguration config = new GuacamoleConfiguration();
config.setProtocol("ssh");
config.setParameter("hostname", hostname);
config.setParameter("port", "22");
// Connect to guacd - everything is hard-coded here.
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
new InetGuacamoleSocket("localhost", 4822),
config
);
// Return a new tunnel which uses the connected socket
return new SimpleGuacamoleTunnel(socket);
}
}
但是当我尝试像localhost:8080/guacamole-tutorial-0.9.9?hostname=localhost一样使用它时,它不起作用。而如果我对相同的值进行硬编码,它就可以正常工作。请帮帮我。