user1912412
user1912412

Reputation: 1

Sending file like xml to a jsp or servlet via http request

I have a requirement where in i have to send an xml file via http request to an jsp page. And at the server side, i have already develop the code to get the inputStream from request object & to store into a file. later i'm processing the xml file to store the data in DB.

Now i need to send an xml file to the jsp. so how to send an xml file from a jsp/servlet to server...

Thanks in advance...

Upvotes: 0

Views: 949

Answers (1)

Sudhakar
Sudhakar

Reputation: 4873

If the Xml file is small , you can store the contents of the xml as String as a request attribute.

Else you could flush the file as response

response.setContentType("text/xml");
PrintWriter out = response.getWriter();
FileInputStream in = new FileInputStream(sample_file);
byte[] buffer = new byte[4096];
int length;
while ((length = in.read(buffer)) > 0){
    out.write(buffer, 0, length);
}
in.close();
out.flush();

Upvotes: 0

Related Questions