I am trying to read output from JSP file using URLConnection
and write it into a html file. Below are the steps I perform:
- Created a link (
http://mydomain/Export.jsp
) - This JSP is divided into three parts
- Header
- Body
- Footer
- Header and Footer are static pages and Body data load using AngularJS which makes request to Server.
Problem:
My application opens the connection successfully with JSP page but before loading the page completely. I mean Angular data, URLConnection.getInputStream()
gets executed and reads only Header and Footer data.
Below is the code snippet.
URL url = new URL(link);
URLConnection connection = url.openConnection();
InputStream inputStream = connection.getInputStream();
InputStreamReader input = new InputStreamReader(inputStream);
File file = new File("output.html");
byte[] buffer = new byte[8 * 1024];
int bytesRead;
try {
OutputStream output = new FileOutputStream(file);
try {
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
} finally {
output.close();
}
} finally {
input.close();
}