| |
23. 51. 1. 用JSP保存表单输入到文件 |
|
index.jsp |
<HTML>
<HEAD>
<TITLE>Please Sign My Guest Book!</TITLE>
</HEAD>
<BODY>
<CENTER>
<H1>Please Sign My Guest Book!</H1>
<FORM ACTION="basic.jsp" METHOD="POST">
Your name:
<INPUT TYPE="TEXT" NAME="TEXT1">
<BR>
<BR>
<BR>
Your comments:
<BR>
<TEXTAREA NAME="TEXTAREA1" ROWS="5" COLS="50"></TEXTAREA>
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit"><INPUT TYPE="RESET" VALUE="Reset">
</FORM>
</CENTER>
</BODY>
</HTML>
|
|
basic.jsp |
<%@ page import="java.io.*" %>
<HTML>
<HEAD>
<TITLE>Thanks for Adding to the Guest Book!</TITLE>
</HEAD>
<BODY>
<H1>Thanks for Adding to the Guest Book!</H1>
Here's what you and others have said:
<BR>
<BR>
<%
String name = request.getParameter("TEXT1");
String text = request.getParameter("TEXTAREA1");
String file = application.getRealPath("/") + "test.txt";
FileWriter filewriter = new FileWriter(file, true);
filewriter.write("<B>Name: </B>" + name + "<BR>");
filewriter.write("<B>Comments: </B><BR>");
filewriter.write(text + "<BR><BR>");
filewriter.close();
%>
<jsp:include page="ch15_04.txt" flush="true"/>
</BODY>
</HTML>
|
|
Download: JSPSaveFormInputToFile.zip( 2 k) |
|