Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1777
  • Last Modified:

java save form to a file

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
dminh01
Asked:
dminh01
  • 2
2 Solutions
 
CEHJCommented:
Just get the field values from the request and append them to a file:

out.println(req.getParameter("a")); //etc
0
 
contactkarthiCommented:
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
 
CEHJCommented:

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
 
dminh01Author Commented:
Thanks CEHJ
How about posting from that file back to the form?


thanks
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now