Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

java save form to a file

Posted on 2007-11-25
4
Medium Priority
?
1,774 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 1000 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 1000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

916 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