在JSP中包含XML代码片段

时间:2013-12-04 15:27:58

标签: xml jsp

如何在JSP中包含一段XML代码而不进行解析?我使用普通的JSP而不使用JSTL或EL。这就是我所做的,但它解析XML代码片段并在页面顶部显示pageViewEventXml,我不想发生这种情况。

home.jsp
==============
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>istore - Home Page</title>
    <jsp:include page="event.jsp"/>
</head>
<body>My Home Page</body>
</html>

event.jsp
============
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="com.istore.utils.GenericUtils"%>
<%
    String pageViewEventXml = GenericUtils.getAttribute(request, "pageViewEventXml");
%>
<![CDATA[<%= pageViewEventXml%>]]>

请指导。

1 个答案:

答案 0 :(得分:0)

不用担心我得到了答案。错过了“脚本”标签

<%@page import="com.istore.utils.GenericUtils"%>
<%
    String pageViewEventXml = GenericUtils.getAttribute(request, "pageViewEventXml");
%>
<script>
    <![CDATA[
      <%= pageViewEventXml%>
    ]] >
</script>