如何解决此警告类型属性(cellpadding)已过时。在HTML5文档中不鼓励使用它

问题描述 投票:4回答:9

我正在使用tapestry开发Web应用程序。我正在使用junit测试套件测试我的应用程序,并使用ant build生成war文件和html报告。在我的html报告文件中,我有以下警告。

Multiple annotations found at this line:
    - Attribute (width) is obsolete. Its use is discouraged in HTML5 documents.
    - Attribute (cellpadding) is obsolete. Its use is discouraged in HTML5 
     documents.
    - Undefined attribute value (0). 
    - Attribute (language) is obsolete. Its use is discouraged in HTML5 documents.

以下是我的测试和报告生成代码。

<target name="test" depends="compile" description="Running Test Suite">
        <mkdir dir="${target.data.dir}"/>
        <mkdir dir="${target.htmlreports.dir}"/>
        <junit fork="no" haltonfailure="no" showoutput="yes" printsummary="true" >
        <test name="${junit.class.name}" todir="${target.data.dir}"/>
        <formatter type="brief" usefile="false"/>
        <classpath refid="classpath.test"/>
        <sysproperty key="ant.home" value="${ant.home}"/>   
        <formatter type="xml"/>
        </junit>
        <junitreport todir="${target.htmlreports.dir}">
        <fileset dir="${target.data.dir}">
        <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="${target.htmlreports.dir}"/>
        </junitreport>
    </target>

这是我的html报告文件之一。

<html xmlns:lxslt="http://xml.apache.org/xslt" xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Unit Test Results: Summary</title>
<link rel="stylesheet" type="text/css" title="Style" href="stylesheet.css">
</head>
<body onload="open('allclasses-frame.html','classListFrame')">
<h1>Unit Test Results.</h1>
<table width="100%">
<tr>
<td align="left"></td><td align="right">Designed for use with <a href="http://www.junit.org/">JUnit</a> and <a href="http://ant.apache.org/">Ant</a>.</td>
</tr>
</table>
<hr size="1">
<h2>Summary</h2>
<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th>Tests</th><th>Failures</th><th>Errors</th><th>Success rate</th><th>Time</th>
</tr>
<tr valign="top" class="Pass">
<td><a title="Display all tests" href="all-tests.html">1</a></td><td><a title="Display all failures" href="alltests-fails.html">0</a></td><td><a title="Display all errors" href="alltests-errors.html">0</a></td><td>100.00%</td><td>0.070</td>
</tr>
</table>
<table border="0" width="95%">
<tr>
<td style="text-align: justify;">
        Note: <em>failures</em> are anticipated and checked for with assertions while <em>errors</em> are unanticipated.
        </td>
</tr>
</table>
<h2>Packages</h2>
<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th width="80%">Name</th><th>Tests</th><th>Errors</th><th>Failures</th><th nowrap>Time(s)</th><th nowrap>Time Stamp</th><th>Host</th>
</tr>
<tr valign="top" class="Pass">
<td><a href="./test/web/app/sampleApp/juint/package-summary.html">test.web.app.sampleApp.juint</a></td><td>1</td><td>0</td><td>0</td><td>0.070</td><td>2013-01-17T04:52:59</td><td>123456</td>
</tr>
</table>
</body>
</html>

请任何人说如何删除此警告。

html junit tapestry
9个回答
1
投票

问题是html报告不是tapestry代码。生成的html报告使用html 4属性,这些属性现在已经过时,如cellpadding,cellspacing等。这些只是junit测试报告。我不会被他们的HTML警告所打扰。


3
投票

我面临同样的问题,我通过使用HTML 4.01 doc类型而不是HTML 5 doctype获得了解决方案。这些警告只是因为HTML5验证器


2
投票

这些警告来自HTML5验证器,并且您正在使用的工具显然在后台运行此类验证器并报告一些报告的错误,并将其显示为警告。通过在HTML文档上直接使用http://validator.nu,还有许多其他错误消息。

但是,警告“未定义的属性值(0)。”是神秘的。关于<table border="0">,这可能是一种奇怪的方式来说明HTML5验证器的说法:“错误:border元素上table属性的值必须是1或空字符串。要调节表格边框的粗细,请改用CSS。“

检查您使用的工具是否具有控制生成的HTML文档中使用的文档类型(doctype)的选项(报告的问题是HTML5草案的错误,但不是根据例如XHTML 1.0),或者生成的HTML代码的类型,或报告问题(例如,“无警告”)。但是,如果可能的话,只是禁用警告可能会掩盖真正的问题。


2
投票

您可以像这样更改代码以删除这样的警告:

<table style="width: 100%;"></table>

1
投票

要详细说明Kanhu的回复,您可以在此处更改Eclipse中的默认HTML文档类型:

Project -> Properties -> Web Content 

1
投票

只需在<html>标记之前包含以下代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

0
投票

添加样式text-align:center;你的HTML元素


0
投票

您可以使用

<table data-width="100%" class="config-header-font">

代替

<table width="100%" class="config-header-font"> 

这个对我有用。

注意:它将删除警告但可能(不确定)更改属性对齐位置。


-2
投票

HTML5中不支持cellpadding属性。请改用CSS。

https://www.w3schools.com/tags/att_table_cellpadding.asp

© www.soinside.com 2019 - 2024. All rights reserved.