繁体   English   中英

通过ur向另一个servlet发送和接收字节数组形式的servlet

[英]send and receive byte array form servlet to another servlet via ur

我有一个字节数组,它是一个消息摘要。 我想通过url将其发送到同一服务器中的另一个应用程序,我不想将其转换为字符串并在另一端拉回数组。

有人可以帮我使用servlet吗?

我的代码像下面

Sendrequauset.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        byte[] encryptedUserName;               
        String username = request.getParameter("username");     
        RsaEncryption encrypt = new RsaEncryption();
        encryptedUserName     = encrypt.encryptClientMassage(username.getBytes(),pk,md);
        String url = "domain/server/GetRequset?username="+encryptedUserName+"";
        response.sendRedirect(url);
    }

}

GetRequset.java

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //i want to get username to byte array from here.I try with request.getParameter("username") but i returns string


    }
URLConnection conn = new URL(URL to send input stream").openConnection();
conn.setDoOutput(true);
OutputStream outs = conn.getOutputStream();
outs.write(pdfBytes);
outs.flush();   
outs.close();

另一方面从请求中获取输入流

request.getInputStream();
URL url = null;

                url = new URL("Your service URL");

            HttpURLConnection connection = null;

                connection = (HttpURLConnection) url.openConnection();


                connection.setRequestMethod("POST");

            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setInstanceFollowRedirects(false); 
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
            connection.setRequestProperty("charset", "utf-8");
            connection.setRequestProperty("Content-Length", "" + 0);
            connection.setUseCaches (false);
            DataOutputStream wr = null;

                wr = new DataOutputStream(connection.getOutputStream ());

            int code = 0;
            try {
                code = connection.getResponseCode();
                wr.flush();
                wr.close();
            } catch (IOException e) {
                logger.error("Error occured while checking the CPR connection", e);
            }
            connection.disconnect();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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