---恢复内容开始---

1.application一般用this.getServletContext()替代

2.appllication有一个非常有用的函数 getRealPath(),获取绝对路径,以便实现jsp的文件操作

String fileName = this.getServletContext().getRealPath("/") + "note" + File.separator + name;

3.保存文件用 PrintStream类对象  

File file = new File(fileName);  

 if (!file.getParentFile().exists()){
    file.getParentFile().mkdir();
 }

 PrintStream ps = null;

ps = new PrintStream(new FileOutputStream(file));

ps.println(fileContent);
   ps.close();

3.读取文件用Scanner类对象

Scanner scan = new Scanner(new FileInputStream(file));

scan.useDelimiter(";");

 StringBuffer buf = new StringBuffer();

 while(scan.hasNext()){

  buf.append(scan.next()).append("<br>");

} 

  scan.close();

<%=buf%>

4.获取服务器环境属性

<%
Enumeration enu = this.getServletContext().getAttributeNames() ; // 取得全部的属性
while(enu.hasMoreElements()){
String name = (String) enu.nextElement() ;
%>
<h4><%=name%> --> <%=this.getServletContext().getAttribute(name)%></h4>
<%
}
%>

最新文章

  1. sharepoint webpart
  2. c++实现螺旋矩阵分析总结
  3. 通信错误:(-1)[描述:无法解析路由器DDNS地址,请检查DDNS状态.] 解析办法
  4. protocol(协议)的一些要点
  5. php中定义类
  6. php curl破解防盗链
  7. 使用MSBUILD 构建时出错 error MSB3086: Task could not find &quot;sgen.exe&quot; using the SdkToolsPath的解决方法
  8. Orchard源码分析(1):插件式的支持——模块和主题
  9. easyui-form添加自定义表单验证
  10. LeetCode_Regular Expression Matching
  11. SE 2014年4月13日
  12. Glide加载圆形图片
  13. CSS 基础
  14. dedecms系统后台登陆提示用户名密码不存在
  15. 需求分析---NABCD
  16. list&lt;实体类&gt;互相嵌套和前台取值问题
  17. linux下安装FTP详细
  18. Python类中的装饰器在当前类中的声明与调用
  19. CentOS 7.4编译安装Nginx1.10.3+MySQL5.7.16
  20. src引入js时添加时间戳参数方法

热门文章

  1. 012 router password
  2. Vue中对获取的数据进行重新排序
  3. C#如何让Listbox支持多选
  4. vue组件之间的通信,父子之间的数据通信
  5. linux服务器上的mysql允许远程连接
  6. python 矩阵
  7. JButton的setRollover出现的奇怪问题
  8. NaN in JavaScript
  9. Silverlight之控件应用总结(二)(4)
  10. [Codeforces 1037E] Trip