在JSP上显示soap响应

时间:2017-06-01 12:50:02

标签: java jsp servlets soap jersey

我是java的新手。 我收到了对我的servlet的soap响应。但是当我尝试在我的JSP页面中显示它时,响应没有正确显示。这就是我如何转发附加到请求的响应,

RequestDispatcher dispatcher = req.getRequestDispatcher("response.jsp");
            req.setAttribute("result", soapResponse);
            dispatcher.forward(req, resp);

response.jsp

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1> Response</h1>
<table>
    <tr>
        <td><%=request.getAttribute("result")%></td>
    </tr>
</table>
</body>
</html>

肥皂反应在这里,

 <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:chargeResponse xmlns:ns2="http://p.com/">
         <return>
            <referralDestination>
               <address>919825010001</address>
            </referralDestination>
            <transactionId>REF59369</transactionId>
            <transactionState>CONFIRMED</transactionState>
         </return>
      </ns2:chargeResponse>
   </soap:Body>
</soap:Envelope>

但是JSP显示是什么,

919825010001 REF59369 CONFIRMED

2 个答案:

答案 0 :(得分:0)

您可以使用原始模式打印它以转义xml响应标记

尝试:

<%!=request.getAttribute("result")%>

或者你可以使用textarea作为@ jozef-chocholacek评论提议

答案 1 :(得分:0)

使用textarea为我工作。

<textarea rows="20" cols="40" style="border:none;">

          <%=request.getAttribute("result")%>   

</textarea>