Calling JSP from a batch file

By: Emiley J.  

If you wondering why in the world should I call a JSP from a batch file then read on. In fact, my problem was to schedule a task that runs every day on a specific time and must generate a report for my management and email the same. Searching the net I was able to accomplish this by combining VB and batch files. But I was not happy with the results. Or to be more specific, my management was not happy with the type of report I was generating in terms of formatting etc.

What the management wanted was a nicely formatted report just as our internal WEB based reports. Now I realised that I have already a JSP that generates the report, now I only have to do two things.

  1. Modify the JSP to instead of displaying, just generate the report in HTML format and then email it
  2.  Secondly I must find a way to schedule this emailing to auto email every day at a specific time.

So I have answered the question as to the necessity of calling a JSP from a batch file. Now that I have decided on what to do, I set search on how to do this. Then I found that batch file by itself cannot accomplish this, therefore I would need a combination of a batch file and a vbscript file (VBS).

So assuming you have a JSP page that generates the report and emails it. Do the following to automate the report generation:

1. Create a text file and copy the following content into it:

Option Explicit
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
objIEA.Navigate "" (This should be changed to your actual url)
objIEA.visible = true
While objIEA.Busy
Set objIEA = Nothing      

2. Rename the text file to report.vbs

3. Create a batch file and name it as report.bat and copy the following content in that batch file.

cscript.exe report.vbs

4. Create a Scheduled task from windows to call this report.bat as per your requirement.

If you are using linux, then you follow the suggestion provided by Goozy in the comments section below

Archived Comments

1. Thank you very much. This is exactly i was looking and was working on a very length process.
View Tutorial          By: Dhyan at 2015-08-26 19:36:57

2. Many thanks!
View Tutorial          By: Bego at 2014-07-10 08:48:02

3. Worked like a charm.

View Tutorial          By: Pete at 2011-02-14 12:24:10

4. great.....
View Tutorial          By: rashid at 2009-12-07 03:22:46

5. Thanks, Just what i was looking for.
View Tutorial          By: Baapu at 2009-10-21 15:21:43

6. Well, I am fortunate to run CentOS 5 - everywhere - even on my laptop.
I trigger a JSP via wg

View Tutorial          By: Goozy at 2009-07-25 11:18:45

7. Just what I was looking for. Great work. thx.
View Tutorial          By: SP Goh at 2008-03-24 01:09:09

Most Viewed Articles (in JSP )

Latest Articles (in JSP)

Comment on this tutorial