I am sending my Ajax Request in the following format
xmlhttp.open("POST","http://172.16.xx.xx:8080/ajax/validate",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(send); //where send is a string retrieved from textarea
This is my Servlet code
ObjectInputStream in =new ObjectInputStream(request.getInputStream());
String inputxmlstring=(String) in.readObject();
I am getting the following exception
java.io.StreamCorruptedException: invalid stream header: 3C3F786D
What is the problem with the code? Is there anything wrong with my request header content type?
EDIT 1
BufferedInputStream in =new BufferedInputStream(req.getInputStream());
byte[] buf=new byte[req.getContentLength()];
while(in.available()>0)
{
in.read(buf);
}
String inputxmlstring=new String(buf);
System.out.println(inputxmlstring);
If I use this code for Servlet I get the following error
14:13:27,828 INFO [STDOUT] [Fatal Error] :1:1: Content is not allowed in prolog
.
14:13:27,843 INFO [STDOUT] org.xml.sax.SAXParseException: Content is not allowe
d in prolog.
EDIT 2
I use this code to parse. The String inputxmlstring has been used in Edit1.
DocumentBuilderFactory fty1 = DocumentBuilderFactory.newInstance();
fty1.setNamespaceAware(true);
DocumentBuilder builder1 = fty1.newDocumentBuilder();
ByteArrayInputStream bais1 = new ByteArrayInputStream(inputxmlstring.getBytes());
Document xmldoc1=builder1.parse(bais1);