【发布时间】:2019-12-12 23:17:26
【问题描述】:
我正在从我的 jsp 代码中调用一个 servlet,并在 javascript 中为该代码设置值。但是每当我向 servlet 发出 POST 请求时,我都会收到以下错误:
The character encoding of the plain text document was not declared.
The document will render with garbled text in some browser
configurations if the document contains characters from outside the US-ASCII range.
The character encoding of the file needs to be declared in the transfer protocol
or file needs to use a byte order mark as an encoding signature.
request.getCharacterEncoding(); 在 servlet 中也变为 null。
我看到了一些类似的问题,并尝试了为他们提供的解决方案,但没有任何效果。 我已经尝试在顶部的 servlet 文件中设置编码。
request.setCharacterEncoding("UTF-8");
我已经在我的 jsp 页面中尝试了<%@page contentType="text/html" pageEncoding="UTF-8"%>。
我已经在表单参数中尝试了 accept-charset="UTF-8"。
//JS Code
function makeSummary() {
var docID = dwr.util.getValue("docId");
var locationId = dwr.util.getValue("locationId");
jq('#fileId').val(docID);
jq('#reqFileName').val(locationId);
document.forms[0].action = "FileDownloadServlet";
document.forms[0].submit();
}
//JSP Code
<form action="FileDownloadServlet" method="POST" id="f1Download" >
<input type="hidden" name="fileId" id="fileId"/>
<input type="hidden" name="reqFileName" id="reqFileName"/>
</form>
//java servlet code
String id = request.getParameter("fileId");
String reqFileName = request.getParameter("reqFileName");
请求中没有数据,我在浏览器控制台中收到上述错误。
奇怪的是我在多个地方使用这种类型的请求,它同时停止工作。似乎不是任何 javascript 或 JSP 文件的问题,它在应用程序级别。
【问题讨论】:
-
我收到以下错误 - 在哪里?浏览器端(浏览器控制台)?服务器端(在您的 servlet 中 - 哪一行,哪个异常)?
-
我在浏览器控制台中遇到上述错误。
-
也尝试了该解决方案,但仍然一无所获
标签: javascript java jsp servlets