【JSP开源代码栏目提醒】:以下是网学会员为您推荐的JSP开源代码-ex9_16.jsp,希望本篇文章对您学习有所帮助。
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!--基于对象流的文件写入-->
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="javabean.ch09.*"%>
<!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_16.jsp?action=submit">
<input type="text" name="name" value="">
发言<input type="text" name="msg" value="">
<input type="submit" name="Submit" value="提交">
</form>
<br>
<%
request.setCharacterEncoding("GB2312");
String author=request.getParameter("name");
String content=request.getParameter("msg");
String action=request.getParameter("action");
if("submit".equals(action)){
File file=new File(request.getRealPath("/")+"chat.txt");
if(!file.exists()){
file.createNewFile();
}
ObjectOutputStream output=new ObjectOutputStream(new FileOutputStream(file));
Article new_msg=new Article();
new_msg.setAuthor(author);
new_msg.setContent(content);
ArrayList list=new ArrayList();
list.add(new_msg);
output.writeObject(list);
output.flush();
output.close();
}
%>
</body>
</html>
上一篇:
ex9_15.jsp
下一篇:
一个人晕着也能去看病打针