2017-06-01 104 views
0

我是新來的java。 我收到了對我的servlet的soap響應。但是當我嘗試在我的JSP頁面中顯示它時,響應沒有正確顯示。這是我轉發響應連接請求,在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> 

SOAP響應是在這裏,

<?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 
+0

參見https://stackoverflow.com/questions/7519618/display-xml-content-in-html-page –

回答

0

使用textarea爲我工作:使用原始模式逃脫XML響應標籤

嘗試打印。

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

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

</textarea> 
0

你可以

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

或者你可以使用文本域作爲@約瑟夫 - chocholacek評論提出

+0

<%!= request.getAttribute( 「結果」)%>給出錯誤。但@jozef建議的答案有效。感謝您的嘗試。 – cmb28