Writing Form Data to Text Files

posted by Scudyen date: Thursday, May 22, 2008 category: JSP
  Featured Story | Printable View | Email It | Comments | Write Comment

This sample of JSP file, first handles all posted data from a web form and write to a text file. We have used Tomcat Server to run our sample code. You could easily edit the source code to use in your application.


The Form Page :

form.html

<html><head>
<title>JSP Examples : Writing Form Data to Text Files</title>
</head>
<body>
<form action="write.jsp" method="post">
Name : <input type="text" name="name">
Message : <textarea name="msg"></textarea>
<input type="submit" name="func" value="Write">
</form>
</body>
</html>

The JSP Page :

write.jsp

<%@page import="java.io.*"%>
<%
String strName = request.getParameter("name");

String msg = request.getParameter("msg");

String func = request.getParameter("func");


if(func!=null){
String strPath = "e:\\\\tomcat\\\\webapps\\\\dotnetindex\\\\example.txt";
File strFile = new File(path);
Writer objWriter = new BufferedWriter(new FileWriter(strFile));
objWriter.write(strName "\\\\n");
objWriter.write(msg "\\\\n");
objWriter.write("===============================\\\\n");
objWriter.flush();
objWriter.close();
}
%>



Happy Coding!


Custom Search



Gazatem Technologies Active News Manager


page counter

Listed with 411asp.net
Listed with 4aspin.com
PHP, ASP, .NET, JSP Resources, Reviews