Solved

java save form to a file

Posted on 2007-11-25
4
1,763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

752 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