在JSP上显示肥皂响应



我是Java的新手。我收到对我的servlet的肥皂回应。但是,当我尝试在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

您可以使用RAW模式打印它以逃脱XML响应标签

尝试:

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

或者您可以使用textarea作为 @jozef-chocholacek评论

使用textarea为我工作。

<textarea rows="20" cols="40" style="border:none;">
          <%=request.getAttribute("result")%>   
</textarea>

最新更新