Hi,
I have web app deployed on weblogic 9.2. There are several reports, each having a input jsp, a output jsp, a java support bean and a export page to export output generated to excel file.

The user feeds input through input jsp. The output jsp reads ip parameters & instantiates a supportbean, which in turn gets input & after processing gives output.

Now, there is a need for some reports to automatically get fired, let say every hour from 9 to 5, and output excel file be emailed.

How it can be implemented?

Dani AI

Generated

A recommended, maintainable approach is to move the report-generation logic out of the JSP and into a reusable backend service (for example, a ReportService class that accepts parameters and returns a File or byte[]). That lets the same code be invoked from the web UI and from any scheduler without going through HTTP, avoiding session/auth brittleness and extra overhead that pointed out.

Scheduling choices and tradeoffs:

  • In-app scheduler (Quartz) — start via a ServletContextListener on deployment. Quartz supports cron-style triggers, JDBC job stores (persistence across restarts) and clustered setups (prevents duplicate runs when configured correctly). Example cron for "top of every hour 9–17": 0 0 9-17 ? * * (or add MON-FRI for weekdays).
  • Container timers (EJB TimerService) — useful if the app already uses EJBs and needs container-managed lifecycle.
  • External scheduler (OS cron + small Java client that posts to an endpoint) — simple to set up but fragile (HTTP auth, error handling, doubled stack). This is the approach suggested; it works but usually less robust than calling the service directly.

Implementation sketch:

  • Extract a ReportService.generateReport(params) that writes an Excel file (use a library) and returns the path/bytes.
  • Create a scheduled job that calls ReportService, then hands the result to a mailer component that sends the file as an attachment (configure SMTP auth/TLS as needed).
  • Example Quartz job skeleton:
    public class ReportJob implements Job {
    public void execute(JobExecutionContext ctx) {
      ReportService svc = ServiceLocator.getReportService();
      File report = svc.generateReport(ctx.getMergedJobDataMap());
      Mailer.sendWithAttachment(report, "report.xlsx");
    }
    }

Operational notes: ensure single-node execution in clusters (DB-backed jobstore or leader election), persist triggers if restarts must not lose schedule, handle retries and logging, enforce timezones/DST, and clean up temp files. If choosing the HTTP firing route, secure the endpoint and add timeouts and retry/backoff.

Recommended Answers

All 2 Replies

For mailing you can check the Java Mail API..
For writing the reports to an Excel proprietary format you will need Apache POI I guess.

Now for it to get automatically fired, I guess you need to create a small application (maybe in Core Java) which will run round the clock, and at specified time intervals (specified in its configuration file or maybe in the database) will fire a request on your JSP page using the required parameters. So for this you will need to know how to perform an HTTP Post / Get request on a remote URL via Core Java, on that.

thanks stephen. This is helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.