【JSP开源代码栏目提醒】:网学会员为广大网友收集整理了,ex9_12.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_12.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();
}
BufferedOutputStream bufferout=new BufferedOutputStream(new FileOutputStream(file));
bufferout.write(content.getBytes());
bufferout.flush();
bufferout.close();
}
%>
</body>
</html>