anand anand -4 years ago 129
SQL Question

How to call sql procedure from an html button?

I have a SQL procedure that generates a util file as its output depending on the input parameters that are passed to it.

I have to pass these parameters from an HTML page from 3 text boxes. There will also be a button, on clicking which, the procedure will be called and the util will be generated.

I thought of doing it in jsp and writing the full procedure there itself. But I want the util file to be opened in WORD the moment it is generated.

I want to know how to call a procedure using button and how to show the util after its generated.

Answer Source

A few guidelines:

  • JSPs work with the request/response lifecycle. So you have to fire a request (GET preferably) in order to do processing on the server-side
  • don't use JSP to write the processing code. Use servlets, or a framework (Struts2/Spring MVC/etc).
  • the processing code would most likely be using JDBC to fetch information from the database.
  • For generating the file, if I correctly assume should be .doc, you can use Apache POI.
  • in your servlet, after generating the file, take a look at this snipper - it tells you what headers you have to send to the browser in order to have the file downloaded (and opened, if the user wants to).

If you are not familiar with JDBC or POI, you will need to go up a steep learning curve. There is no magical way to generate a file in a desired format.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download