lundi 21 avril 2014

Overwrite the text file using jsp


Vote count:

0




I am trying to overwrite a text file which contains 6 lines of data by inserting 6 different lines of data. Here is my form.



<form method="POST" action="write.jsp">
Name: <input type="text" name="name1" size="20" /><br>
Price: <input type="text" name="price" size="20" /><br>
Due time: <input type="text" name="DueTime" size="20" /><br>
Location: <input type="text" name="Location" size="20" /><br>
Photo Url: <input type="text" name="url" size="20" /><br>
Description: <input type="text" name="desc" size="20" /><br>
<input type="submit" name="submit" onclick="window.close()"/>
</form>


After user clicks on submit, it will go to write.jsp, which is shown below.



String name = request.getParameter("name1");
String price = request.getParameter("price");
String DueTime = request.getParameter("DueTime");
String Location = request.getparameter("Location");
String url = request.getparameter("url");
String desc = request.getparameter("desc");


String paths="somepath/hotel1.txt";

FileWriter filewriter = new FileWriter(paths, true);

filewriter.write(name + System.getProperty("line.separator"));
filewriter.write(price + System.getProperty("line.separator"));
filewriter.write(DueTime + System.getProperty("line.separator"));
filewriter.write(Location + System.getProperty("line.separator"));
filewriter.write(url + System.getProperty("line.separator"));
filewriter.write(desc + System.getProperty("line.separator"));
filewriter.close();


But somehow it does work, can anyone help me to fix this?



asked 31 secs ago






Aucun commentaire:

Enregistrer un commentaire