Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Write file to server

Write file to server

Write file to server

I have a page with a button on it, when pressed I want a servlet to get some data from the database and then create a file with that data and save it to the server and then prompt the user to download the file.

I have the page with the button on it and I have the servlet that gathers all the data, but what I need to know is how do I call a servlet from a page like invokeBusinessObject("string"), and how do I write my servlet to create the file on the server and prompt the user to download it?

Also when the servlet creates the file where does it put it (/SilverStream/Objectstor/General/).

SS 2.54
Oracle 8i


RE: Write file to server

Don't create the file on the server, but rather stream it directly to the client!

Use resp.setContentType(String) to set the ContentType to something browsers wouldn't know about.

The page is  a SilverStream Page or is it a JSP or static HTML?

If the former, create an eventhandler for the button:

private void handle_<controlname>_pageActionPerformed(ActionEvent evt) throws Exception
//... handle buttonclick.

Create the Servlet inside the SilverStream environment (as a business object), give it a Page alias to call (triggers->URLs) in the format "SilverStream/Pages/<yourservletalias>.html" so you can then use showPage("p<yourservletalias>.html"); from pageGenerateBegin().

This would have all the action in the servlet, the event handler need only check the input and maybe set things in the session object for the servlet to process (formdata etc.).

If you're using JSP and Servlet, create them as a J2EE application outside of SilverStream and package them as a WAR file.
Upload this using silvercmd deploywar <server>:<port> <database> <warfile> -f <deploymentdescriptor> -v5 -o
the deployment descriptor takes the form:

<?xml version="1.0"?>
<!DOCTYPE warJarOptions PUBLIC "-//SilverStream Software, Inc.//DTD J2EE WAR Deployment Plan//EN" "deploy_war.dtd">

        <sessionTimeout type="String">2</sessionTimeout>

Creating a JNDI entry to the database known as myDatabase.
This is referenced in web.xml as:

<?xml version="1.0"?>

the dataSource in the SilverStream deployment descriptor must be a database known to SilverStream (add using the designer for example) so the server can create a connection using the proper JDBC driver.

I think you can probably also use a mixed approach where the Page would call a Servlet in an external web application, but that would entail redirecting the HTTP response to the servlet and you'd possibly (haven't tested this) loose the HTTP session so you'd have to pass the parameters as Servlet request parameters instead (small price to pay for the added flexibility maybe).
You'd then replace showPage("<yourpage.html>") with res.sendRedirect("<yourservleturi>") which should be placed in pageRequestEnd(req,res) for the Page (you'd set a flag that redirection is to take place and the URI of the servlet in the eventhandler).

RE: Write file to server

Thanks, jwenting your reply has helped but I have not explained fully my problem.

Yes what you said will work but I am writing the entire page myself and printing it out to a rawHTMLMode() Label.  I then use enumeration to get the parameters.  Because I have multiple buttons on the page I cannot use event triggers to call the servlet from the page.

I have managed to get the button working properly calling the servlet in the pageRequestEnd(), but what my servlet does is creates an html page and sets the contenet type to "application/msword" so that the browsers opens the page in MS Word.

My final output has to be in MS Word, and the problem that still exists is that when I call the servlet in the pageRequestEnd() it opens the page as an html document and not as word document.  If I call the servlet directly <servleturl> the browser will open the document in word.

How can I call my servlet from the page so that it will open as a MS Word document and not as an html page?

RE: Write file to server

You can use event triggers for multiple controls (I've done so myself and it is working).
But indeed if you're writing the buttons as standard HMTL controls rather than placing them in the designer that's unlikely to work (most I've ever done is use rawHTMLMode() labels to add dynamically generated Javascript or language dependent texts).

If the servlet is being shown as HTML despite you setting the contentType yourself to Word it might be SilverStream is messing around resetting it back to HMTL for you.
Quite likely if it's coded as a business Object in SilverStream rather than coded as a J2EE application object and placed in a WAR file.

As to where it writes files, I'm not certain.
Would depend on your setup I guess, but certainly not inside the SilverStream database. It would be somewhere on the server filesystem.
Unless you have another HTTP server running that can read from that location you wouldn't be able to serve the file and you may not want to go that way as it would have to run on another port, something we're trying to get rid of here as some of our customers have indicated they can't access anything except port 80 because of firewall issues (for now we've put in a notice to that regard, in the end we'd like to move the other server to another machine with its own ip address and DNS entries).

RE: Write file to server

Hey jwenting thanks for your replies, they've helped.

I figured out a way to call the servlet and show up in the MS Word format.  In my buttons that I manually create I wrote some javascript that will fire and open a new window calling the servlet and this proved to be working.

As far as writing the file to the server, I tried this and was able to get it working but when opened on different PC's the format changes.  So the workaround we created was that there is only one user who will be pulling the reports from the servlet so that user is responsible for calling the servlet and saving the file as a .doc not .html file in word.  When calling the servlet and saving in .doc Word converts the file itself.

As a note when I created the report I first created a template in Word and then saved it as a web page.  Then I opened the .html file word created in Notepad and examined the way Word does its conversions for HTML and used these when writing HTML from my servlet.

You may not be interesed in all these facts but I wanted to put them here for reference for anyone else trying to do the same.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close