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:
Code:
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:
Code:
<?xml version="1.0"?>
<!DOCTYPE warJarOptions PUBLIC "-//SilverStream Software, Inc.//DTD J2EE WAR Deployment Plan//EN" "deploy_war.dtd">
<warJarOptions>
<warJar>
<warJarName>additional.war</warJarName>
<isEnabled>true</isEnabled>
<sessionTimeout type="String">2</sessionTimeout>
<URL>
<el>/extra</el>
</URL>
<resourceReferenceList>
<resourceReference>
<name>jdbc/mydb</name>
<type>javax.sql.DataSource</type>
<dataSource>myDatabase<dataSource>
</resourceReference>
</resourceReferenceList>
</warJar>
</warJarOptions>
Creating a JNDI entry to the database known as myDatabase.
This is referenced in web.xml as:
Code:
<?xml version="1.0"?>
<web-app>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
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).