正在从我的Servlet中删除请求XML括号

时间:2018-04-10 01:50:45

标签: java jsp

我有一个jsp,form标签内有以下文本区域,以便我可以将XML提交给servlet:

<tr>
    <td align="center">
        <textarea name="xmlreqdoc" rows="20" cols="50"></textarea>
    </td>
</tr>

文本区域是我提交请求XML的地方,我在servlet类中检索提交的XML,如下所示:

String requestXML = pReq.getParameter("xmlreqdoc");

pReq只是HttpServletRequest

现在,我遇到的问题是,当我通过JSP文本区域提交XML时,String requestXML会返回所有删除的括号,即>< XML和我不明白为什么?

    <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/common/doctype_html.inc" />
<html>
    <head>
        <!-- meta http-equiv="Content-Type" content="text/html; charset=utf-8"-->
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.5.1.min.js" ></script>
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-ui-1.8.13.custom.min.js" ></script> 
        <script type="text/javascript">
            function postXMLToOMV2(){
                        formomv2.submitaction.value="getClientGuid";
                        formomv2.action="<%=request.getContextPath()%>/user/create/OMTestClient.do";                        
                        var $form = $('#formomv2');             
                        $.post($form.attr("action"), $form.serialize());


            }
        </script>
    </head>
    <body>
        <center>
            <FORM accept-charset="UTF-8" name="formomv2" method="post" action="#" id="formomv2">
                <table>
                    <tr>
                        <td>
                            <h1>Please enter the ECS DM Messaging</h1>
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                            <textarea name="xmlreqdoc" rows="20" cols="50"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                            TransId: <INPUT type="text" name="transId" value=""/>
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                            Encrypted: <INPUT type="checkbox" name="encrypted" value="Y"/>
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                            <INPUT type="submit" name="submit" value="submitRequest" onclick="postXMLToOMV2()"/>
                        </td>
                    </tr>
                </table>
                <input type="hidden" name="submitaction" value="" />
            </FORM>
        </center>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

您提交表单的方式似乎是为了使某些字符不会从XML字符串中转义。在提交之前,请尝试serializing您的表单。

由于你正在使用Jquery,你可以尝试这样的事情:

   function postXMLToOMV2(){

         formomv2.submitaction.value="getClientGuid";
         formomv2.action="<%=request.getContextPath()%>/user/create/OMTestClient.do";

         var $form = $('#formomv2');             
         $.post($form.attr("action"), $form.serialize());

         // im not sure where you have declared 'formomv2' but if you have you could probably also just do the following:
         //  $.post(formomv2.attr("action"), formomv2.serialize());

            }