开发者

Best way to generate xml using jstl

Very simple question about jstl. Consider Map which return by Controller/Servlet. I would like to generate xml output for client. Should i use stan开发者_JS百科dard jstl tags or there is more elegant way to do it ?

Right now i created jsp with this text

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<?xml version="1.0" encoding="utf-8"?>
<response>
   <c:forEach var="entry" items="${msg}">
    <${entry.key}> 
      <![CDATA[${entry.value}]]>
     </${entry.key}>
   </c:forEach>
</response> 

It should work, but i believe there is better way to do it


When my response is XML I usually skip JSTL and use JAXB (i.e. write directly to output stream from servlet/controller).


That's how I generate all of my XHTML web pages, and XHTML is XML. You might want to use <c:out> or ${fn:escapeXml()} to escape special XML characters.


<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>

Here is an example from another stack overflow question

or this question

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜