Calling JSP from a batch file

By: Emiley J. Emailed: 1768 times Printed: 2516 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


1. View Comment

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

View Tutorial          By: SP Goh at 2008-03-24 01:09:09
2. View Comment

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.

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

Thanks, Just what i was looking for.

View Tutorial          By: Baapu at 2009-10-21 15:21:43
4. View Comment


View Tutorial          By: rashid at 2009-12-07 03:22:46
5. View Comment

Many thanks!

View Tutorial          By: Bego at 2014-07-10 08:48:02

Your name (required):

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

Your sites URL (optional):

Your comments:

More Tutorials by Emiley J.
Error generating from manifest
ERROR 1251: Client does not support authentication protocol requested by server; consider upgrading MySQL client
IIS and Tomcat - how to configure to work together
PHP Warning: Unknown(): Unable to load dynamic library '/usr/local/php4/lib/php/extensions/no-debug ......
Adding your own Application icon for your J2ME application (jar file)
Creating Menus in Code using
Traversing all files in a directory using Ruby
Using Proxy to connect to URLs in Ruby
POST a form in Ruby
Reading URL content using Ruby (HTTP)
dRuby client/server mode sample program
Benchmark module in Ruby
encoding and decoding in Ruby using Base64 Module
Module Abbrev in Ruby
Standard Library Packages in Ruby

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
What are the different scopes in JSP?
JSP Example to connect to MS SQL database and retrieve records
Sending Email using JSP
Automatically Refreshing a JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
The JSP Program running first Time.
Embedding java codes in jsp sciptlets
JSP Program for display Date
The Advantages of Servlets Over “Traditional” CGI
The Servlet Life Cycle
Enabling Expression Language Evaluation in JSP
Calling JSP from a batch file
Deploying an Individual JSP on Tomcat
Most Emailed Articles (in JSP)
What is JSP?
Declaring variable in JSP
Techniques for form editing
A Simple Servlet Generating Plain Text
An Example Using Servlet Initialization and Page Modification Dates
Text Object
The Basic Syntax Expression Language in JSP
Disabling Scriptlets in JSP using web.xml
The BodyTag Interface in JSP
What are the different scopes in JSP?
Sending Email using JSP
Using a DataSource from WebLogic in a JSP
Getting HTTP Request Headers in a JSP