开发者

JSP - write XML to console

开发者 https://www.devze.com 2023-01-19 10:33 出处:网络
I have large JSP page, and there is XML creation on it. For debug purpose i need to write that XML to console.

I have large JSP page, and there is XML creation on it.

For debug purpose i need to write that XML to console.

What is the easiest way to do this from JSP?

thank you very much on your time and energy, best regards

EXAMPLE:

...

My.jsp

...
    <portfolio>
      <stock>
        <symbol><c:out value="${bean.prop1}"/></symbol>
        <name><c:out value="${bean.prop2}"/></name>
        <price><c:out value="${bean.prop3}"/>开发者_JS百科</price>
      </stock>
    </portfolio>
...

....

Now i want to print entire XML to console to see if it is OK


You can't do this from the JSP on. Your best bet is to create a Filter which wraps the response using HttpServletResponseWrapper wherein you copy the response output. Finally log the captured response output. Long story short, here's a code example: Capture and log the response body.

If you want to log partial response, you've to parse the captured output yourself.


It wouldn't be pretty, but you could use a StringBuffer in your JSP and build up your XML in the StringBuffer. Once it's built, issue the following commands:

<%
// write to log
System.out.print(buffer.toString);

// emit into JSP response
out.print(buffer.toString);
%>
0

精彩评论

暂无评论...
验证码 换一张
取 消