Calling JSP from a batch file

By Emiley J. Viewed: 31742 times Emailed: 213 times Printed: 219 times Bookmark and Share



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 "http://192.17.12.10/emailreport.jsp" (This should be changed to your actual url)
objIEA.visible = true
While objIEA.Busy
Wend
objIEA.Quit
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 or cron job in your Unix servers to call this report.bat as per your requirement.




Comments(4)


1. Just what I was looking for. Great work. thx.

By: SP Goh at 2008-03-24 01:09:09
2. Well, I am fortunate to run CentOS 5 - everywhere - even on my laptop.
I trigger a JSP via wget from cron every hour. Works just perfect.

You can also trigger a "scheduler.jsp" for example once a minute, and can that way have a custom scheduler that kicks in, if some job is due. In short: Schedule everything from Java/JSP - instead of fiddling with lots of cron-jobs. Just one simple cron-job.

By: Goozy at 2009-07-25 11:18:45
3. Thanks, Just what i was looking for.

By: Baapu at 2009-10-21 15:21:43
4. great.....

By: rashid at 2009-12-07 03:22:46

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:


Enter Code:
The Captcha image

Latest Tutorials

[2009-09-01]IIS and Tomcat - how to configure to work together
[2008-12-09]Drawbacks of the JSP Model 1 Architecture
[2008-12-09]What are the different scopes in JSP?
[2008-11-24]Using a DataSource from WebLogic in a JSP
[2008-11-24]Getting HTTP Request Headers in a JSP
[2008-11-24]Automatically Refreshing a JSP
[2008-11-24]Embedding a QuickTime movie in a JSP
[2008-11-24]Embedding MP3 audio file in a JSP
[2008-11-23]Writing your first JSP page
[2008-11-23]Deploying an Individual JSP on Tomcat
[2008-08-13]Using UTF-8 in JSP / ASP / HTML pages.
[2008-03-24]Calling JSP from a batch file
[2008-03-23]Sending Email using JSP
[2007-10-12]JSP Example to connect to MS SQL database and retrieve records
[2007-10-12]JSP Example to connect to MS SQL database using Tomcat Connection Pool

More Latest News

Most Viewed Articles (in last 30 days)
JSP Program for display Date
JSP Example to connect to MS SQL database and retrieve records
What are the different scopes in JSP?
NotifyUtil::java.net.ConnectException: Connection refused: connect
JSP Example to connect to MS SQL database using Tomcat Connection Pool
Sending Email using JSP
Getting Started with JSP
Comparison operators in JSP
Using a DataSource from WebLogic in a JSP
Writing your first JSP page
Form processing in JSP
Calling JSP from a batch file
The Advantages of JSP
What is JSP?
JSP Tags for SQL to connect to a database
Most Emailed Articles (in last 30 days)
Form Object
JSP Program for display Date
Click to Activate and Use this control
Sending Email using JSP
Example Using Initialization Parameters
Cookies using JSP or Java Bean
Sessions in JSP
JSP Example to connect to MS SQL database and retrieve records
The best way to avoid security vulnerabilities with new server
Retrieving a Portion of a String
Working with Status Bar Messages
NotifyUtil::java.net.ConnectException: Connection refused: connect
JavaScript Security
Server-side plug-Ins
What is JSP?