【JSP开源代码栏目提醒】:网学会员--在 JSP开源代码编辑为广大网友搜集整理了:ex9_10.jsp绩等信息,祝愿广大网友取得需要的信息,参考学习。
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!--分行写入文件-->
<%@ page import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>JSP通用范例大全</title>
</head>
<body>
<center><font size=5>分行写入文件</font></center>
<br><hr><br>
<form name="chat" method="post" action="ex9_10.jsp">
写入文件的内容<input type="text" name="content" value="">
<input type="submit" name="Submit" value="提交">
</form>
<br>
<%
request.setCharacterEncoding("GB2312");
String content=request.getParameter("content");
if(content!=null){
File file=new File(request.getRealPath("/")+"chat.txt");
if(!file.exists()){
file.createNewFile();
}
FileWriter fw=new FileWriter(file,true);
BufferedWriter bfw=new BufferedWriter(fw);
bfw.write(content);
bfw.newLine();
bfw.flush();
bfw.close();
fw.close();
}
%>
</body>
</html>