欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

通过流访问JSP并且动态添加参数  

程序员文章站 2024-03-16 11:24:34
...
fileDownloadPath = http://localhost:8303/aws_file_server/print_label.jsp  
 URL url = new URL(fileDownloadPath);
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);

        PrintWriter outStream = new PrintWriter(connection.getOutputStream());
        outStream.print("username=" + username);//xxxxx
        outStream.print("&password=" + password);//12345678
        outStream.print("&xml=" + xml); //<?xml version="1.0" encoding="UTF-8" ?>
        <PrintLabelInfo><IdType>id_type_party</IdType>
        <StartPrintNumber>1</StartPrintNumber><OrderBy>name</OrderBy><EnqSeq>27099272</EnqSeq><PrintOpt>0</PrintOpt></PrintLabelInfo>
        
        outStream.print("&source=" + PrintInfo.SOURCE_WEB);//WEB
        outStream.print("&token=" + token);//0
        outStream.print("&queue_category=" + queueCategory); // LABEL
        outStream.print("&agent_code=" + agentCode);//xxxxx				outStream.close();
        InputStream in = connection.getInputStream(); ==> jump to print_label_now.jsp

上面的        InputStream in = connection.getInputStream(); ==> 跳转到新的URL中
下面的: 获取新参数值
String newUsername = request.getParameter("username");
    String newPassword = request.getParameter("password");
    String source = request.getParameter("source");
    String token = request.getParameter("token");
    String xml = request.getParameter("xml");
    String queueCategory = request.getParameter("queue_category");
    String agentCode = request.getParameter("agent_code");
    if (agentCode == null && xml != null && !"".equals(xml)) {
        agentCode = getValueByAttribute(xml, "agent_code");
    }