怎么让struts2返回xml形式的数据,jsp页面以xml格式显示数据
展开全部
直接返回XML的参考下面的代码,更多参考http://lixueli26.javaeye.com/blog/698946
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
//HttpSession session = request.getSession();
response.setContentType("text/xml;");
PrintWriter out = response.getWriter();
URL url = new URL(request.getParameter("url"));
DataInputStream dis = new DataInputStream(url.openStream());
String sLine;
while ((sLine = dis.readLine()) != null){
out.println(sLine);
}
out.flush();
out.close();
// 不返回结果
return null;
}
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
//HttpSession session = request.getSession();
response.setContentType("text/xml;");
PrintWriter out = response.getWriter();
URL url = new URL(request.getParameter("url"));
DataInputStream dis = new DataInputStream(url.openStream());
String sLine;
while ((sLine = dis.readLine()) != null){
out.println(sLine);
}
out.flush();
out.close();
// 不返回结果
return null;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询