1

I am calling a servlet from my jsp code and setting the value in javascript for that code. But whenever i am putting POST request to the servlet, I am getting the below error:

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(); is also coming null in servlet.

I have seen some similar questions and tried the solutions given for them but nothing worked. I have tried setting encoding in servlet file on the top.

 request.setCharacterEncoding("UTF-8"); 

I have tried <%@page contentType="text/html" pageEncoding="UTF-8"%> in my jsp page.

I have tried accept-charset="UTF-8" in form parameters.

//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");

No data is coming in request and I am getting above mentioned error in the browser console.

The strange thing is I was using this type of request at multiple places and it stopped working at the same time. Doesn't seem like an issue of anyone javascript or JSP file, it is on application level.

Vicky Rathee
  • 69
  • 11

1 Answers1

0

try using below as a very first line in your jsp file.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
Onkar Musale
  • 909
  • 10
  • 25