Java 错误 - 多次出现具有不同值的“contentType”是非法的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24743585/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:38:02  来源:igfitidea点击:

Error - illegal to have multiple occurrences of 'contentType' with different values

javajspjakarta-eeglassfish-4

提问by james

I have a dynamic web project in Eclipse which I run on Glassfish4. In the project, there is an index.jsp file given below. When I run this jsp on the server, I get the error:

我在 Eclipse 中有一个动态 Web 项目,它在 Glassfish4 上运行。在项目中,下面给出了一个 index.jsp 文件。当我在服务器上运行这个 jsp 时,出现错误:

org.apache.jasper.JasperException: /index.jsp(1,1) PWC5988: Page directive: illegal to have multiple occurrences of 'contentType' with different values (old: text/html, new: text/html; charset=ISO-8859-1)

org.apache.jasper.JasperException: /index.jsp(1,1) PWC5988: Page directive: illegal to have multiple occurrences of 'contentType' with different values (old: text/html, new: text/html; charset=ISO-8859-1)

This is an internal server error with the description - The server encountered an internal error that prevented it from fulfilling this request.

这是一个带有描述的内部服务器错误 - 服务器遇到内部错误,阻止它完成此请求。

<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="css/designs.css">
</head>
<body>

Content

</body>
</html>

I looked in google and other sites, but found no working solution. The server log stack trace also did not help. Please help me.

我查看了谷歌和其他网站,但没有找到可行的解决方案。服务器日志堆栈跟踪也没有帮助。请帮我。

采纳答案by Skylion

The issue is that you have "Content-Type" declared twice (as "text/html"). This against specifications and is causing your website to throw an error.

问题是您将“Content-Type”声明了两次(作为“text/html”)。这违反规范并导致您的网站引发错误。

You just can't use both tags simultaneously. The HTTP protocol also provides the Content-Type encoding. So unless you know how your website is serving those pages, don't mess with Content-Type.

您不能同时使用这两个标签。HTTP 协议还提供了 Content-Type 编码。所以除非你知道你的网站是如何为这些页面提供服务的,否则不要乱用 Content-Type。