【问题标题】:calling servlet from applet?从applet 调用servlet?
【发布时间】:2011-01-11 21:24:19
【问题描述】:

我正在尝试从applet 调用servlet 下面是调用代码

ObjectOutputStream outputToServlet = null;
            try {
                //String xmlToSign = this.getParameter("xmltosign");
                String xmlToSign ="<?xml version=\"1.0\" encoding=\"UTF-8\"?> <root> <name> hello world</name></root> ";
                URL signServlet = new URL("http://localhost:8084/SignXMLDemo/mtservlet");
                URLConnection servletConnection = signServlet.openConnection();
                servletConnection.setDoInput(false);
                servletConnection.setDoOutput(true);
                servletConnection.setUseCaches(false);
                servletConnection.setDefaultUseCaches(false);
                servletConnection.setRequestProperty("Content-Type", "application/octet-stream");
                outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
                String encodedValue = new BASE64Encoder().encode(xmlToSign.getBytes());
                outputToServlet.writeObject(encodedValue);
                outputToServlet.flush();
                outputToServlet.close();
                JOptionPane.showMessageDialog(this, "XML successfully signed and sent to server.");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage());
            } finally {
                try {
                    outputToServlet.close();
                } catch (IOException ex) {
                    Logger.getLogger(SignApplet.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

代码的问题是没有被调用的 servlet 可以帮助解决我在代码中缺少的内容。 URL 是正确的,因为它可以从我使用的浏览器中调用,即 9 windows 7 机器。

阿卜杜勒·哈利克

【问题讨论】:

  • 小程序必须对小程序签名的证书做任何事情
  • 未签名的小程序只能用于同一个域。
  • 我有一个单独的小程序 jar 文件,并且可能 tomcat 应用程序是一个不同的项目,不同的代码库是一个问题吗?小程序是自签名的
  • 我使用简单的 java 套接字测试了小程序,它工作正常,但我不明白为什么即使 URL 正确且每一行代码都成功执行,它也没有与网络服务器建立连接跨度>
  • 您需要调用并使用getInputStream() 才能真正触发请求。另见stackoverflow.com/questions/2793150/…

标签: java tomcat servlets applet tomcat6


【解决方案1】:

在我们从打开的流中读取字节之前,不会调用服务器端代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    相关资源
    最近更新 更多