Solved

java save form to a file

Posted on 2007-11-25
4
1,749 Views
Last Modified: 2008-02-01
hi there
I am learning servlet and trying to save the data entered from a form to a file before it generate the html. Can you please help me how I can do that
Also how will I use the saved file to upload to the form


Thanks
0
Comment
Question by:dminh01
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 20347118
Just get the field values from the request and append them to a file:

out.println(req.getParameter("a")); //etc
0
 
LVL 17

Accepted Solution

by:
contactkarthi earned 250 total points
ID: 20347132
to write to a file see the below link
http://www.exampledepot.com/egs/java.io/WriteToFile.html

to get the values from the form in a servlet
http://www.exampledepot.com/egs/javax.servlet/GetReqParam.html

combine both of them to get what you need
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 20347165

PrintWriter out = new PrintWriter(new FileWriter("formvals.properties"));

for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) {

	String name = (String)e.nextElement();

	out.println(name + "=" + req.getParameter(name));

}

out.close();

Open in new window

0
 

Author Comment

by:dminh01
ID: 20347515
Thanks CEHJ
How about posting from that file back to the form?


thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now