在 Eclipse 中编辑 xhtml jsp 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/541335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Editing xhtml jsp files in Eclipse
提问by wds
I've got some jsp files that are supposed to output xhtml. They seem to have the correct doctype etc but Eclipse is not parsing the xhtml attributes. For instance for the root element:
我有一些应该输出 xhtml 的 jsp 文件。他们似乎有正确的文档类型等,但 Eclipse 没有解析 xhtml 属性。例如对于根元素:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
I get the warning: "Undefined attribute name (xmlns)." What's the best way to solve this in Eclipse?
我收到警告:“未定义的属性名称 (xmlns)。” 在 Eclipse 中解决这个问题的最佳方法是什么?
edit: The doctype for this particular file was wrong apparently, it was set to:
编辑:这个特定文件的文档类型显然是错误的,它被设置为:
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Which does not exist obviously. Eclipse is now complaining about taglib tags though, i.e.:
这显然不存在。Eclipse 现在抱怨 taglib 标签,即:
<%@taglib prefix="s" uri="/struts-tags" %>
generates the warning: "Tag (jsp:directive.taglib) should be an empty-element tag."
生成警告:“标签 (jsp:directive.taglib) 应该是一个空元素标签。”
采纳答案by Ian Devlin
That seems odd, I use the same in Eclipse but with PHP and it works fine.
这看起来很奇怪,我在 Eclipse 中使用了相同的方法,但在 PHP 中使用它并且运行良好。
What is the DOCTYPE that you use? I've used
您使用的 DOCTYPE 是什么?我用过
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
回答by agnul
If you're going to ouput xml (in my understanding xhtml isxml) then you should be using the jsp documentsyntax, for instance your
如果您要输出 xml(在我的理解中 xhtml是xml),那么您应该使用 jsp文档语法,例如您的
<%@taglib prefix="s" uri="/struts-tags" %>
should instead be a namespace in some top-level tag. For the project I'm working on all the jsp are like this
应该是某个顶级标签中的命名空间。对于我正在做的项目,所有的jsp都是这样的
<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root version="2.0"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"/>
<jsp:text><![CDATA[<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">]]>
</jsp:text>
<html xmlns="http://www.w3.org/1999/xhtml">
...
</html>
</jsp:root>
回答by abc
If you're using JSF, check if you got the view tag twice.
如果您使用的是 JSF,请检查您是否获得了两次视图标记。
That's how I solved the message: Undefined attribute name "xmlns:ui"
这就是我解决消息的方式: Undefined attribute name "xmlns:ui"
回答by Romain Linsolas
Eventually, you can install JBoss Tools (update sitefor Eclipse, guides) which provides quite good XHTML / JSP editors.