JSP中拼装数据为XML出现的问题
来源:互联网 发布:vmware没有mac选项 编辑:程序博客网 时间:2024/05/22 06:33
一、应用背景
JSP取得Servlet中放入request的List,将List中的数据拼装成XML。以下代码在Eclipse的内置浏览器中显示为xml,没有问题。
/** * 新闻Servlet * @author 徐越 * */public class ListServlet extends HttpServlet{ private static final long serialVersionUID = 1L; private VideoNewsService vs = new VideoNewsServiceImpl(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<VideoNews> news = vs.readNews(); request.setAttribute("lstnews", news); request.getRequestDispatcher("/WEB-INF/pages/news.jsp").forward(request, response); }}
<%@ page language="java" contentType="text/xml; charset=utf-8" pageEncoding="utf-8"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><?xml version="1.0" encoding="UTF-8"?><videoNews> <c:forEach items="${lstnews}" var="n"> <news id="${n.id }"> <title>${n.title }</title> <length>${n.timeLength }</length> </news> </c:forEach></videoNews>
二、发现问题
火狐中报错:XML解析错误:XML 或文本声明不在实体的开头
chrome报错:XML declaration allowed only at the start of the document
根据错误信息,可以知道XML声明<?xml version="1.0" encoding="UTF-8"?>必须在文档的开头。
三、解决问题
方法一
将page、taglib、xml同时放在第一行即可,一个接一个的后面。虽然不好看,但是解决问题哦。
方法二
有网友朋友给出好的方法,在jsp首行放置<%@ page trimDirectiveWhitespaces="true"%>
- JSP中拼装数据为XML出现的问题
- JSP中拼装数据为XML出现的问题
- Android中使用XmlSerializer拼装XML数据
- java相关记录1----将数据拼装成xml标准的字符串,转化为伪excel。
- Jsp页面中ajax提交数据:及hbm.xml文件中出现的错误
- 编码为 UTF-8 的JSP 文件中出现非法字符  问题
- 解决JSP中出现乱码的问题
- jsp中include出现的问题
- 拼装xml
- jsp程序在向sql server中插入数据时出现的问题 急!!!!!!!!
- myeclipse中为struts配置dbcp数据池连接sqlserver时出现的问题
- js中拼装Html时 在onclick 中传值出现问题解决办法,及替换全部的方法
- jsp中处理数据的问题
- 输入框数据的初始化拼装
- springmvc接口返回xml数据出现中文乱码的问题
- json_decode转换json数据为数组出现的问题!
- C# 将bit位数据拼装为byte
- 解决mysql--jsp中出现的中文乱码问题
- 完整的Set-Cookie 头
- 作者为何要写《简约之美》这本书?程序员们又能从中学到什么呢?
- SQL转化
- \r只回车不换行
- jodd使用示例
- JSP中拼装数据为XML出现的问题
- 10个iPhone开发网站、论坛、博客
- python的赋值、浅拷贝和深拷贝
- Android 开 发 资 源 分 享
- The Message Type in ABAP
- 指来指去(2)
- 常用的 字符串 函数 2012-12-13 9:31
- 送给入门初学者的6条建议
- 病人心理需求