当前位置: 首页 > 图文教程 > 网络编程 > JSP > 在JSP中写text文件

JSP
我认为JSP有问题(上)
我认为JSP有问题(下)
jsp“抓”网页代码的程序
关于在bean里面打印html的利弊看法
bean里面如何打印到html页面
jdbc3中的RowSet 接口规范
Apusic Application Server1.0中jsp源代码泄漏漏洞
Unify的eWave ServletExec拒绝服务漏洞
通过提交超长的GET请求导致IBM HTTP Server远程溢出
在HTTP请求中添加特殊字符导致暴露JSP源代码文件
Resin 1.2 重要源代码暴露漏洞
多中WEB服务器的通用JSp源代码暴露漏洞
Tomcat 暴露JSP文件内容
IBM WebSphere Application Server 暴露JSP文件内容
JRun 2.3.x 范例文件暴露站点安全信息
BEA WebLogic 暴露源代码漏洞
IBM WebSphere Application Server 3.0.2 存在暴露源代码漏洞
Tomcat 3.1 存在暴露网站路径问题
Sun Java Web Server 能让攻击者远程执行任意命令
Netscape 修复 JAVA 安全漏洞

在JSP中写text文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-02   浏览: 42 ::
收藏到网摘: n/a

使用PrintWriter对象即可写Text文件。

请参考以下示例:

<%@ page import="java.io.*" %>
<%
String str = "print me";
//always give the path from root. This way it almost always works.
String nameOfTextFile = "/usr/anil/imp.txt";
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.println(str);
//clean up
pw.close();
} catch(IOException e) {
out.println(e.getMessage());
}
%>

现在,打开imp.txt加以查看,字符串"print me"应该已经写入。

还有另一种方法,使用IN16标记库的file tag,可参考http://sourceforge.net/project/?group_id=1282.
其示例的语法为:
<ext:file action="write|append|create|copy|move|delete|rename|read" from="<%= myfilename %>">