简体   繁体   中英

calling servlet from applet?

i am trying to call servlet from applet below is the calling code

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);
                }
            }
        }

the issue with the code is that servlet in not being called can any one help in this what i am missing in the code. The URL is correct as it can be called from browser i am using ie 9 windows 7 machine.

Abdul Khaliq

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM