Java servlet allows you to save some field value from your HTML form in the file. For example, with this component you may collect subscription addresses etc. User's input can be e-mailed also to the given address.
You must set this servlet as an action parameter for your form. Servlet collects posted data and proceed them according to own configuration file. Configuration file describes how save your data as well as your mail settings.
How to use it:
a) copy saveDataPackage.jar into WEB-INF/lib directory
b) describe servlet in your web.xml file:
You can pass configuration file as a parameter to this servlet and use it
in this form:
E.g. some like this:
please type your e-mail address:
please type your e-mail address:
or in html-tags:
<br>please type your e-mail address:
<form action="http://your_host/servlet/SaveDataServlet?c:\files\my_config.txt" method="post">
<input type="Text" name="what"> <input type="submit" value="Subscribe">
or you may describe configuration file as an initial parameter (parameter name is config):
and use servlet in this form:
Configuration file is a text file describes servlet's settings. You can save this file anywhere on your server. Configuration file has got free format, but description of any parameter must starts with an appropriate reserved word on the new line. Each line has the following form:
Current version supports the following list of parameters:
Data: describes full path for data
file. By default it is savedata.txt in the root directory of your
Field: describes the name of the field from html-form. By default it is what
Reply: you can set here url for the page that will displayed after data saving. See Notes below.
Encoding: localization support. You can set character encoding for input parameters here. Default value is ISO-8859-1. E.g.:
You can also e-mail user's input to some address. Here is a list of parameters you can use for mail settings:
Mailhost: describes your smtp host.
This parameter is mandatory
Port: describes smtp port. By default it is 25.
Domain: describes your domain. This parameter is mandatory.
From: describes source address. This parameter is mandatory.
To: describes destination address. This parameter is mandatory.
Cc: describes cc settings for your letter
Subject: set letter's subject
Body: set letter's body
Attach: you can set here a list of files you need to attach to composed letter.
When you describe contents of any mail-related fields,
you can use also constructions like $data as a reference for user's input.
E.g. for the above mentioned example you can set some like this:
here $data will be replaced with the actual value of user's input.
When you set attachments you can set a list of commas separated files.
1. Servlet's configuration file can be saved anywhere on your server. E.g. if you are using SaveData?config line we assume this file is saved under the root directory of your servletrunner. But you can of course always use the full path for setting config file location: SaveData?/home/users/my_file (or SaveData?c:\users\my_file)
2. If reply value starts with http than request will be redirected to that site. Otherwise servlet assumes a local resource and forwards request.
sample of configuration file: saveconf
© Coldbeans Software Comments?
See also JSOS - the largest collection of servlets and filters.