我正在尝试存储来自jsp页面的数据,其中包含许多字段 服务类型 线上 离线等,基于将数据写入文件的选择,
现在我能够静态存储选择值的存储位置和未选择值的空值。
由于
答案 0 :(得分:2)
JSP
用于文本字段,另一个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>
和在文本文件中存储输入归档值。
<%@ page import="java.io.*" %>
<HTML>
<HEAD>
</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>
很高兴帮助您随意发表意见。