JSP 中输出xml

<%@ page language="java" import="java.util.*,java.io.*"
	contentType="text/xml; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String userName=request.getParameter("username");
	String content=request.getParameter("content");
	response.setContentType("text/xml;charset=UTF-8");
	PrintWriter writer = response.getWriter();
	writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
	writer.write("<comment username=\""+userName+"\">");
	writer.write("<content>"+content+"</content>");
	writer.write("</comment>");
	response.flushBuffer();
%>

你可能感兴趣的:(JSP 输出 xml)