JSP中如何将textarea的内容另存为一个txt文件
jsp中点击按钮弹出一个另存为的对话框将页面的textarea中的内容保存在一文件中(不一定是txt)求大神指点怎么弄,完事加分...
jsp中点击按钮弹出一个另存为的对话框 将页面的textarea中的内容保存在一文件中(不一定是txt)
求大神指点怎么弄,完事加分 展开
求大神指点怎么弄,完事加分 展开
3个回答
2016-02-02 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
JSP中将textarea的内容另存为一个txt文件方法如下:
<HTML>
<HEAD>
<META content="text/html;charset=gb2312" http-equiv="Content-Type">
</head>
<body>
<script type="text/javascript">
function saveas()
{
var winSave = window.open();
winSave.document.open ("text/html","utf-8");
winSave.document.write (document.getElementById("dataarea").value);
winSave.document.execCommand ('SaveAs',true,'test.txt','.txt');
winSave.close();
}
</script>
<textarea id="dataarea">
Test, just a test
</textarea>
<input type=button value="另存为" onclick="saveas()">
</body>
</html>
<HTML>
<HEAD>
<META content="text/html;charset=gb2312" http-equiv="Content-Type">
</head>
<body>
<script type="text/javascript">
function saveas()
{
var winSave = window.open();
winSave.document.open ("text/html","utf-8");
winSave.document.write (document.getElementById("dataarea").value);
winSave.document.execCommand ('SaveAs',true,'test.txt','.txt');
winSave.close();
}
</script>
<textarea id="dataarea">
Test, just a test
</textarea>
<input type=button value="另存为" onclick="saveas()">
</body>
</html>
展开全部
提交到后台得到textarea的内容,再用io流写进文件里面
追问
io流写进文件里面?怎么写啊 求代码指点 用FileInputStream么
把内容写进文件内 怎么写来着? 求指点啊 急会加分
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String client = request.getHeader("User-Agent");
String appachName="下载.txt";
if (client.indexOf("MSIE") > 0) {
response.setContentType("application/octet-stream;charset=utf-8");
appachName = new String(appachName.getBytes("GBK"),"ISO-8859-1");
appachName = "attachment; filename=\"" +appachName+ "\"";
} else {
response.setContentType("application/octet-stream;charset=UTF-8");
appachName = new
String(appachName.getBytes("utf-8"),"ISO-8859-1");
appachName = "attachment; filename=\"" +appachName+ "\"";
}
response.setHeader("content-disposition", appachName);
response.setHeader("Cache-Control", "must-revalidate");
String content = request.getParameter("textarea 的 Name 值");
OutputStream fos = response.getOutputStream();
fos.write(content.getBytes());
fos.flush();
fos.close();
试试看
String appachName="下载.txt";
if (client.indexOf("MSIE") > 0) {
response.setContentType("application/octet-stream;charset=utf-8");
appachName = new String(appachName.getBytes("GBK"),"ISO-8859-1");
appachName = "attachment; filename=\"" +appachName+ "\"";
} else {
response.setContentType("application/octet-stream;charset=UTF-8");
appachName = new
String(appachName.getBytes("utf-8"),"ISO-8859-1");
appachName = "attachment; filename=\"" +appachName+ "\"";
}
response.setHeader("content-disposition", appachName);
response.setHeader("Cache-Control", "must-revalidate");
String content = request.getParameter("textarea 的 Name 值");
OutputStream fos = response.getOutputStream();
fos.write(content.getBytes());
fos.flush();
fos.close();
试试看
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询