在浏览器控制台中获取错误:未声明纯文本文档的字符编码



我正在调用我的JSP代码的servlet,并在该代码中设置JavaScript中的值。但是,每当我将帖子请求提交servlet时,我会遇到以下错误:

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中也无效。

我已经看到了一些类似的问题,并尝试了为他们提供的解决方案,但没有任何效果。我尝试在顶部的Servlet文件中进行编码。

 request.setCharacterEncoding("UTF-8"); 

我在JSP页面中尝试了<%@page contentType="text/html" pageEncoding="UTF-8"%>

我在表单参数中尝试过接受-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文件的问题,它在应用程序级别。

尝试使用以下作为JSP文件中的第一行。

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

相关内容

最新更新