提交application/x-www-form-urlencoded类型数据

提交application/x-www-form-urlencoded类型数据


发送application/x-www-form-urlencoded接收通知

举例:发送通知以及接收通知

说明:此demo非常简化,使用tomcat服务器运行,本文说明:

  • 包含文件
    1.SendNotification.jsp:发送通知页面,表单提交数据的类型为multipart/x-www-form-urlencoded
    2.RecvNotification.jsp:接收通知页面
    3.页面简单使用了Bootstrap样式
  • 接收参数方式 :request.getParameter(“param”);

Demo下载地址:

http://download.csdn.net/detail/musuny/8761707


关键代码

  • SendNotification.jsp

    <form action="RecvNotification.jsp" method="post" enctype="application/x-www-form-urlencoded">
    <table class="table-responsive">
        <tr>
            <td>
                <span>message:</span>
                <textarea  rows="5" class="form-control" name="message" id="message" content=""
                           placeholder="例如:PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8%2BPE1vQmFvQWNjb3VudCBNZXNzYWdlVHlwZT0iTm90aWZ5UGF5UmVzdWx0Ij48T3JkZXJObz5NMjAxNTA1NTYwOTg4MzY8L09yZGVyTm8%2BPFRyYWRlQW10PjUwMDAuMDA8L1RyYWRlQW10PjxDdXN0UGFyYW0%2BMTIzPC9DdXN0UGFyYW0%2BPFRyYWRlVGltZT48L1RyYWRlVGltZT48L01vQmFvQWNjb3VudD4="></textarea>
                <br/>
            </td>
        </tr>
        <tr>
            <td>
                <span>signature:</span>
                <textarea  class="form-control" rows="5" name="signature" id="signature"
                       placeholder="例如:33D13212133895FB6AF9C1556948996AC4A636F6A98E1E9DDE6296D0179E7466BF04C44F97EA3E6A29B69FED16C36C14BD8BFAFCB04806579573DC2F560DDB9820B4CC242038B33BC444C2C143D76EA9AD4F8F824EB9D1B5963DC867AA8B0C11D5B7A2D981151642E6DEDA845D94D9731ECD42E668AEA0D7EDD00C5817EF5DE8"
                        content=""></textarea>
                <br/>
            </td>
        </tr>
    </table>
    
    <input type="button" onclick="setDefaultValue()" style="margin-left: 200px;" value="使用默认值" class="btn-lg btn-success"/>
    <input type="submit" value="模拟发送通知" style="margin-left: 200px;" class="btn-lg btn-danger"/>
    </form>
  • RecvNotification.jsp

<%
    String ip = request.getHeader("X-Forwarded-For");
    if (ip == null)
        ip = request.getRemoteHost();
    Map param = new HashMap();
    param.put("ip", ip);
    String message = request.getParameter("message");
    param.put("message", message);
    String signature = request.getParameter("signature");
    param.put("signature", signature);
    String messageDecode = URLDecoder.decode(message, "UTF-8");
    String base64decoded = new String(new BASE64Decoder().decodeBuffer(messageDecode), "GBK");
    param.put("base64decoded", base64decoded);
    request.setAttribute("notification", param);
    Map notification = (Map) request.getAttribute("notification");
%>
<h2>接收到的支付通知消息</h2>

<div class="table-responsive">
    <table border="1" class="table table-bordered table-hover">
        <thead>
        <td class="col-lg-1 ">字段名</td>
        <td class="col-lg-6 ">接收到的值</td>
        <td class="col-lg-3 ">说明</td>
        </thead>
        <tr>
            <td class="col-lg-1 ">IP地址</td>
            <td class="col-lg-6 "><%=notification.get("ip")%>
            </td>
            <td class="col-lg-3 ">支付通知方IP地址</td>
        </tr>
        <tr>
            <td class="col-lg-1 ">message</td>
            <td class="col-lg-6 "><textarea rows="5" class="form-control" cols="300" readonly><%=notification.get("message")%></textarea>
            </td>
            <td class="col-lg-3 ">message经过base64编码以及URLEncode UTF-8编码</td>
        </tr>
        <tr>
            <td class="col-lg-1 ">message明文</td>
            <td class="col-lg-6 "><textarea rows="5" class="form-control" cols="300" readonly><%=notification.get("base64decoded")%></textarea>
            </td>
            <td class="col-lg-3 ">message经过base64解码以及URLEncode UTF-8解码</td>
        </tr>
        <tr>
            <td class="col-lg-1">signature</td>
            <td class="col-lg-6 "><textarea rows="5" class="form-control" cols="300" readonly><%=notification.get("signature")%></textarea>
            </td>
            <td class="col-lg-3 ">签名信息</td>
        </tr>
    </table>
</div>

我的联系方式

  • Q Q:1250052380
  • 邮箱:[email protected]

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。