I have a situation where I have a series of similar JSPs, each of which is called from a servlet based upon an option entered by a user.
However, I would like to adjust these JSPs so that they can be additionally called in batch from a program which runs hourly on the server, and write the JSP output to text file.
Can anyone tell me how this might be done at all?
I am thinking along the lines of:
URL url = new java.net.URL("http://127.0.0.1/myServlet");
URLConnection con = url.openConnection();
Or is there a better way?
OK: I must be doing something very foolish here because this doesn't appear to work: I have a batch program which runs every hour and it contains the following code:
try {
URL url = new java.net.URL("http://127.0.0.1:8084//myApp//myServletMapping?par=parValue");
URLConnection connection = url.openConnection();
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setDoInput(true);
InputStream response = connection.getInputStream();
}
catch (Exception ex) {
logger.error("Error calling servlet in batch", ex);
}
According to my understanding of the instructions in this tutorial, the above should be enough to trigger the get method in the servlet which is mapped to by myServletMapping in the code above. This servlet's get method contains a simple System.out.println("Here"); which I would expect to see.
What am I doing wrong?