java - How to call a servlet from a batch program? -


i have situation have series of similar jsps, each of called servlet based upon option entered user.

however, adjust these jsps can additionally called in batch program runs hourly on server, , write jsp output text file.

can tell me how might done @ all?

i thinking along lines of:

url url = new java.net.url("http://127.0.0.1/myservlet"); urlconnection con = url.openconnection(); 

or there better way?

ok: must doing foolish here because doesn't appear work: have batch program runs every hour , contains 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 understanding of instructions in this tutorial, above should enough trigger method in servlet mapped myservletmapping in code above. servlet's method contains simple system.out.println("here"); expect see.

what doing wrong?

or there better way?

not really. that's basic gets. servlet "called" when server receives http, , that's proposed code do.

you could use library such httpunit, or different programming language, it's going boil down sending http request.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -