sumitshah123
asked on
Store Html form values submitted by user into a text file on the server.
I want the JSP code to save the values submitted by the user by filling the html form into a text file on the unix solaris server. Please give me just a short sample code of how it is done. I will award the full points immediately.
Survey is a seven question HTML form with a jsp submission.
All questions are required. On submission form should write a tab or pipe (|) delimited file to the /formdata directory located on the root. Form will reside on the root.
If a user chooses "Other" on questions 2,3 or 5 they must fill in the blank after "Other". For users selecting "Yes" on question 6 an e-mail address is optional.
Below is the actual form :
1. How often do you log in to our Web Commerce site? (Select One)
a. At least once a day
b. At least once a week
c. At least once a month
2. What is your position within your company? (Select One)
a. Clerical
b. Management
c. Field Sales
d. Inside Sales
e. Shipping & Receiving
f. Other ______________________
3. Are there other individuals within your organization using this tool? (Select All That Apply)
a. Clerical
b. Management
c. Field Sales
d. Inside Sales
e. Shipping & Receiving
f. Other ______________________
4. What additional tools could we add to improve the Web Commerce site? Please rank the following tools in importance. One being the most important. (Rank 1 - 10)
a. New Housing Data
b. Product Information
c. Statement & Invoice Payment
d. Sales & Commission Reports
e. Product Availability
f. Regional Industry Data
g. National Industry Data
h. Sales & Revenue Analysis Tools
i. Selling Tools and Tips
j. Business Management Tips
5. Do you use a Web Commerce site with other companies? (Select One)
a. Kohler
b. Moen
c. Delta
d. Sears
e. Other __________________________ __________ __
f. No
6. Are there other individuals within your organization the In-Sink-Erator Web Commerce site would be helpful too? (Select One)
a. Yes (please supply e-mail address)
b. No
7. Additional Comments -
(Open Text Field)
Rgds,
Sumit Shah.
Survey is a seven question HTML form with a jsp submission.
All questions are required. On submission form should write a tab or pipe (|) delimited file to the /formdata directory located on the root. Form will reside on the root.
If a user chooses "Other" on questions 2,3 or 5 they must fill in the blank after "Other". For users selecting "Yes" on question 6 an e-mail address is optional.
Below is the actual form :
1. How often do you log in to our Web Commerce site? (Select One)
a. At least once a day
b. At least once a week
c. At least once a month
2. What is your position within your company? (Select One)
a. Clerical
b. Management
c. Field Sales
d. Inside Sales
e. Shipping & Receiving
f. Other ______________________
3. Are there other individuals within your organization using this tool? (Select All That Apply)
a. Clerical
b. Management
c. Field Sales
d. Inside Sales
e. Shipping & Receiving
f. Other ______________________
4. What additional tools could we add to improve the Web Commerce site? Please rank the following tools in importance. One being the most important. (Rank 1 - 10)
a. New Housing Data
b. Product Information
c. Statement & Invoice Payment
d. Sales & Commission Reports
e. Product Availability
f. Regional Industry Data
g. National Industry Data
h. Sales & Revenue Analysis Tools
i. Selling Tools and Tips
j. Business Management Tips
5. Do you use a Web Commerce site with other companies? (Select One)
a. Kohler
b. Moen
c. Delta
d. Sears
e. Other __________________________
f. No
6. Are there other individuals within your organization the In-Sink-Erator Web Commerce site would be helpful too? (Select One)
a. Yes (please supply e-mail address)
b. No
7. Additional Comments -
(Open Text Field)
Rgds,
Sumit Shah.
You'll want to stick a new line character on the end and open the FileOutputStream in append mode http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileOutputStream.html#FileOutputStream(java.io.File,%20boolean) if you want to collect information from more than one person.
ASKER
i made the html form but i want to loop through the entire form in one loop( like for each in asp) and save all input type and form values to the text file.
any help..???
Sumit.
any help..???
Sumit.
this should help you:
<%@ page import="java.io.*,java.uti l.*" %>
<%
BufferedWriter bw = new BufferedWriter(new FileWriter("c:/temp/out.tx t"));
Enumeration enum = request.getParameterNames( );
String line = "";
while (enum.hasMoreElements()) {
String paramName = (String)enum.nextElement() ;
line = paramName + ": ";
String[] values = request.getParameterValues (paramName );
for (int i = 0; i < values.length; i++) {
line += values[i];
if (i != (values.length - 1)) line += ", ";
}
bw.write(line, 0, line.length());
bw.newLine();
}
bw.close();
%>
<%@ page import="java.io.*,java.uti
<%
BufferedWriter bw = new BufferedWriter(new FileWriter("c:/temp/out.tx
Enumeration enum = request.getParameterNames(
String line = "";
while (enum.hasMoreElements()) {
String paramName = (String)enum.nextElement()
line = paramName + ": ";
String[] values = request.getParameterValues
for (int i = 0; i < values.length; i++) {
line += values[i];
if (i != (values.length - 1)) line += ", ";
}
bw.write(line, 0, line.length());
bw.newLine();
}
bw.close();
%>
ASKER
hi,
i m geting this below error when i tried the above good. Any help ???
500 Servlet Exception
java.io.FileNotFoundExcept ion: out.txt (Permission denied)
at java.io.FileOutputStream.o pen(Native Method)
at java.io.FileOutputStream.< init>(File OutputStre am.java:17 6)
at java.io.FileOutputStream.< init>(File OutputStre am.java:70 )
at java.io.FileWriter.<init>( FileWriter .java:46)
at __27esumitshah4u._submit__ jsp._jspSe rvice(/~su mitshah4u/ submit.jsp :5)
at com.caucho.jsp.JavaPage.se rvice(Java Page.java: 74)
at com.caucho.jsp.Page.subser vice(Page. java:485)
at com.caucho.server.http.Fil terChainPa ge.doFilte r(FilterCh ainPage.ja va:181)
at com.caucho.server.http.Inv ocation.se rvice(Invo cation.jav a:291)
at com.caucho.server.http.Run nerRequest .handleReq uest(Runne rRequest.j ava:341)
at com.caucho.server.http.Run nerRequest .handleCon nection(Ru nnerReques t.java:268 )
at com.caucho.server.TcpConne ction.run( TcpConnect ion.java:1 36)
at java.lang.Thread.run(Threa d.java:543 )
i m geting this below error when i tried the above good. Any help ???
500 Servlet Exception
java.io.FileNotFoundExcept
at java.io.FileOutputStream.o
at java.io.FileOutputStream.<
at java.io.FileOutputStream.<
at java.io.FileWriter.<init>(
at __27esumitshah4u._submit__
at com.caucho.jsp.JavaPage.se
at com.caucho.jsp.Page.subser
at com.caucho.server.http.Fil
at com.caucho.server.http.Inv
at com.caucho.server.http.Run
at com.caucho.server.http.Run
at com.caucho.server.TcpConne
at java.lang.Thread.run(Threa
your web server is not having permission to write on disk.... under what user profile your web server is running??
Check the permissions for your user profile and see if you have file write permission.
Regards
Check the permissions for your user profile and see if you have file write permission.
Regards
if you are on solaris and storing to /var/tmp or something then do something like this just to get up and running
chmod 777 -R /var/tmp
chmod 777 -R /var/tmp
ASKER
i have using free jsp hosting on www.mycgiserver.com for testing. i have given 777 permision to the output file.
any clues??
any clues??
Hmm... that server won't give you permission of c:\temp\ as this directory is not under your control...
try just using "out.txt"... it should create the text file in your webapp folder where your should have autority to write.
regards
try just using "out.txt"... it should create the text file in your webapp folder where your should have autority to write.
regards
login to the console of you service provider. go to the root of your webapplication. make the file "out.txt" then type:
chmod 777 out.txt
next type: pwd
copy this path and put it here:
BufferedWriter bw = new BufferedWriter(new FileWriter("path/out.txt") );
replace path with that full thing
chmod 777 out.txt
next type: pwd
copy this path and put it here:
BufferedWriter bw = new BufferedWriter(new FileWriter("path/out.txt")
replace path with that full thing
ASKER
i created a directory 'outt' manually.
and the code is :
<%@ page import="java.io.*,java.uti l.*" %>
<%
BufferedWriter bw = new BufferedWriter(new FileWriter("/outt/out.txt" ));
Enumeration enum = request.getParameterNames( );
String line = "";
while (enum.hasMoreElements()) {
String paramName = (String)enum.nextElement() ;
line = paramName + ": ";
String[] values = request.getParameterValues (paramName );
for (int i = 0; i < values.length; i++) {
line += values[i];
if (i != (values.length - 1)) line += ", ";
}
bw.write(line, 0, line.length());
bw.newLine();
}
bw.close();
response.setContentType("t ext/html") ;
out.println("<html>");
out.println("<br><head></h ead><br><b ody><br>We have received your reponse.<br>");
out.println("</form><br></ body><br>< /html>");
out.close();
%>
it still give me below error :
500 Servlet Exception
java.io.FileNotFoundExcept ion: /outt/out.txt (No such file or directory)
at java.io.FileOutputStream.o pen(Native Method)
at java.io.FileOutputStream.< init>(File OutputStre am.java:17 6)
at java.io.FileOutputStream.< init>(File OutputStre am.java:70 )
at java.io.FileWriter.<init>( FileWriter .java:46)
at __27esumitshah4u._submit__ jsp._jspSe rvice(/~su mitshah4u/ submit.jsp :5)
at com.caucho.jsp.JavaPage.se rvice(Java Page.java: 74)
at com.caucho.jsp.Page.subser vice(Page. java:485)
at com.caucho.server.http.Fil terChainPa ge.doFilte r(FilterCh ainPage.ja va:181)
at com.caucho.server.http.Inv ocation.se rvice(Invo cation.jav a:291)
at com.caucho.server.http.Run nerRequest .handleReq uest(Runne rRequest.j ava:341)
at com.caucho.server.http.Run nerRequest .handleCon nection(Ru nnerReques t.java:268 )
at com.caucho.server.TcpConne ction.run( TcpConnect ion.java:1 36)
at java.lang.Thread.run(Threa d.java:543 )
and the code is :
<%@ page import="java.io.*,java.uti
<%
BufferedWriter bw = new BufferedWriter(new FileWriter("/outt/out.txt"
Enumeration enum = request.getParameterNames(
String line = "";
while (enum.hasMoreElements()) {
String paramName = (String)enum.nextElement()
line = paramName + ": ";
String[] values = request.getParameterValues
for (int i = 0; i < values.length; i++) {
line += values[i];
if (i != (values.length - 1)) line += ", ";
}
bw.write(line, 0, line.length());
bw.newLine();
}
bw.close();
response.setContentType("t
out.println("<html>");
out.println("<br><head></h
out.println("</form><br></
out.close();
%>
it still give me below error :
500 Servlet Exception
java.io.FileNotFoundExcept
at java.io.FileOutputStream.o
at java.io.FileOutputStream.<
at java.io.FileOutputStream.<
at java.io.FileWriter.<init>(
at __27esumitshah4u._submit__
at com.caucho.jsp.JavaPage.se
at com.caucho.jsp.Page.subser
at com.caucho.server.http.Fil
at com.caucho.server.http.Inv
at com.caucho.server.http.Run
at com.caucho.server.http.Run
at com.caucho.server.TcpConne
at java.lang.Thread.run(Threa
/outt/out.txt is not correct..
use "pwd" to find the correct path
use "pwd" to find the correct path
ASKER
hey, i m using cuteftp...how do i get the path??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
toooooo much..............
I appreciate your efforts tbone......:)
I appreciate your efforts tbone......:)
thanks Kuldeepchaturvedi... i only signed up because it sounded like a cool free service... you should check it out. but no doubt, seriously too much on this one... hahaha.
try this code below...
File f = new file("/formdata/whateverfi
FileOutputStream fo = new FileOutputStream(f);
String ans1=request.getParameter(
ans1+="|";
fo.write(ans1.getBytes());
String ans2=request.getParameter(
ans2+="|";
fo.write(ans2.getBytes());
........ and so on..
at last
fo.close();
As far as mandetory fields goes.. you can use javascript or can put jsp validations before you come for writing the file.
Hope this helps