例如如下代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://www.mldn.cn/jst/core"%> <%@ taglib prefix="x" uri="http://www.mldn.cn/jst/x"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <c:import var="add" url="/ch13/address.xml" charEncoding="GBK"/> <x:parse var="addressXml" doc="${add}"/> <x:choose> <x:when select="$addressXml//name/@id='lxh'"> <h3>编号是lxh的名称是:<x:out select="$addressXml/addresslist/linkman/name"/></h3> </x:when> <x:otherwise> <h3>啥也不是了!</h3> </x:otherwise> </x:choose> </body> </html>
运行的时候出现这种异常:
七月 15, 2013 8:40:34 上午 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.xml.sax.SAXParseException; systemId: jstl:; lineNumber: 6; columnNumber: 4; 元素类型 "name" 必须由匹配的结束标记 "</name>" 终止。
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
你查啥去?没得查,就仅仅是因为你的c:import使用了GBK,而页面以及address.xml都是用的UTF-8!
又比如昨天,我遇到这个问题
HTTP Status 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: org.xml.sax.SAXParseException; systemId: jstl:; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。
代码是这样的:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://www.mldn.cn/jst/core"%> <%@ taglib prefix="x" uri="http://www.mldn.cn/jst/x"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <c:import var="add" url="/ch12/address.xml" charEncoding="UTF-8"/> <x:parse var="addressXml" doc="${add}"/> <h3>姓名:<x:out select="$addressXml/addresslist/linkman/name"/>(编号:<x:out select="$addressXml/addresslist/linkman/name/@id"/>)</h3> <h3>邮箱:<x:out select="$addressXml/addresslist/linkman/email"/></h3> </body> </html>
最后查明原因,仅仅是因为c:import的url中,ch12应该换为才ch13!仅仅因为我把路径写错了而已,但是它却报了个跟路径貌似毫无关系的exception!