从JSP进行XML声明之前的空白 [英] Whitespace before XML declaration from JSP

查看:133
本文介绍了从JSP进行XML声明之前的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对JSP输出进行完整的XHTML过渡验证,但是遇到了麻烦.标题的顶部看起来像这样:

I'm trying to achieve full XHTML transitional validation of my JSP output but I've hit a snag. The top of the header looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

它包含在如下语句中:

<jsp:include>
  <jsp:attribute name="page"><owportal:page name="/style/portal/header.jsp" /></jsp:attribute>
</jsp:include>

< owportal:page>标签会检查一些不同的路径,以便在需要时可以使用特定于项目的标头覆盖它.这样做的问题是,必须先声明owportal taglib,然后才能使用它,在XML声明之前插入空白行并引起验证警告.

The <owportal:page> tag checks a few different paths so that we can override it with a project-specific header if need be. The problem with this is the owportal taglib needs to be declared before it can be used, inserting a blank line before the XML declaration and causing a validation warning.

我尝试使用jsp:output来生成XML声明,运气不佳.有人可以告诉我我是否在正确的轨道上吗?

I have tried using jsp:output to generate an XML declaration without much luck. Can anyone let me know if I'm on the right track here?

更新:

目前我正在尝试类似的事情

Currently I'm trying something like this

<%@ taglib uri="/WEB-INF/yadda/yadda" prefix="yadda" %>

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" version="2.0">
  <jsp:output omit-xml-declaration="false" doctype-root-element="html"
              doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
</jsp:root>

<html>...

< jsp:root>上出现错误无效的标准动作".线.不是最有用的错误消息.听起来好像我以某种方式使用了错误的标签.我正在运行Tomcat 6,因此JSP版本应该不会有问题.有人可以看到我在做什么吗?是< jsp:root>打算包裹< html>?

And I am getting an error "Invalid standard action" at the <jsp:root> line. Not the most helpful error message. Sounds like I'm using the tag wrong somehow perhaps. I'm running Tomcat 6 so it shouldn't be a problem with the JSP version. Can anyone see what I'm doing wrong? Is <jsp:root> meant to wrap around <html>?

推荐答案

如果我对您的理解正确,那么您尝试在JSP的最顶部包含这个jsp:include,但是在此过程中,您正在引起JSP会在XML序言之前的顶部输出一些空白.

If I understand you correctly, then you are trying to include this jsp:include at the very top of the JSP, but, in the process, you are causing the JSP to output a few bits of whitespace at the top before the XML preamble.

在这种情况下,我只是要确保JSP那里没有空格:

In cases like this, I have just resorted to making sure the JSP has no whitespace up there:

<jsp:include><jsp:attribute name="page"><owportal:page name="/style/portal/header.jsp" /></jsp:attribute></jsp:include>[your content continues here, not on next line!]...

但是我认为您在问一个不同的问题,即如何告诉JSP输出XML声明.为此,您想从这样的东西开始(假设这里您使用的是最新的JSP规范,例如2.1)...

But I think you are kind of asking a different question, which is how to tell a JSP to output an XML declaration. To do that, you want to start with something like this (assuming here you're using a recent JSP spec like 2.1)...

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" version="2.1">
  <jsp:output
          omit-xml-declaration="false" doctype-root-element="html"
          doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
          doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
...

这是处理从JSP(X)文件输出XML的更正确的方法-更明确.

This is the more right way to handle outputting XML from a JSP(X) file -- more explicit.

这篇关于从JSP进行XML声明之前的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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