在jsp页面中显示xhtml内容 [英] Displaying xhtml content in a jsp page

查看:168
本文介绍了在jsp页面中显示xhtml内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示XHTML内容的JSP页面.我的JSP页面顶部包括以下几行:

I have a JSP page that displays XHTML content. I have included the following lines at the top of my JSP page:

<?xml version="1.0" encoding="UTF-8"?>
<% response.setContentType("application/xhtml+xml"); %>
<% request.setCharacterEncoding("UTF-8"); %>

如果我将以上行更改为:

If I change the above line to:

<?xml version="1.0" encoding="UTF-8"?>
<% response.setContentType("application/xhtml+xml;charset=UTF-8"); %>
<% request.setCharacterEncoding("UTF-8"); %>

页面停止呈现并抛出XML解析错误,例如我的javascript中的某个冒号"或未找到处理指令"等.

The page stops rendering and throws XML parsing error such as "semi colon expected somewhere in my javascript" or "processing instruction not found" etc etc.

从response.setContentType中删除"charset = utf-8"将使页面呈现.唯一的问题是→显示为问号?"

Removing "charset=utf-8" from response.setContentType makes the page render. The only problem is that → shows up as a questin mark "?"

推荐答案

您可能具有以下代码:

<script type="text/javascript"> if (a && b) </script>

在XHTML模式下为禁止,但在text/html模式下为必需.您可以在将XHTML发送为text/html认为有害的中找到此问题的说明.

which is forbidden in XHTML mode, but required in text/html mode. You'll find explanation of this problem in Sending XHTML as text/html Considered Harmful.

和类似的代码:

<a href="foo?bar&baz">

在任何版本的HTML或XHTML中均不允许使用

.它必须始终写为:

is not allowed in any version of HTML or XHTML. It must always be written as:

<a href="foo?bar&amp;baz">

显然,您不是在使用XML序列化器生成页面(它不会让您创建无效的实体或编码不正确的字符),因此,我建议您改用HTML 4 Strict或HTML5-as- text/html更适合手工编码的标记.

Apparently you're not generating page using XML serializer (it wouldn't let you create invalid entities or improperly encoded characters), therefore I suggest that you use HTML 4 Strict or HTML5-as- text/html instead, which are more appropriate for hand-coded markup.

这篇关于在jsp页面中显示xhtml内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆