jsp学习笔记 - 内置对象 application
---恢复内容开始---
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>
<%
}
%>
最新文章
- sharepoint webpart
- c++实现螺旋矩阵分析总结
- 通信错误:(-1)[描述:无法解析路由器DDNS地址,请检查DDNS状态.] 解析办法
- protocol(协议)的一些要点
- php中定义类
- php curl破解防盗链
- 使用MSBUILD 构建时出错 error MSB3086: Task could not find ";sgen.exe"; using the SdkToolsPath的解决方法
- Orchard源码分析(1):插件式的支持——模块和主题
- easyui-form添加自定义表单验证
- LeetCode_Regular Expression Matching
- SE 2014年4月13日
- Glide加载圆形图片
- CSS 基础
- dedecms系统后台登陆提示用户名密码不存在
- 需求分析---NABCD
- list<;实体类>;互相嵌套和前台取值问题
- linux下安装FTP详细
- Python类中的装饰器在当前类中的声明与调用
- CentOS 7.4编译安装Nginx1.10.3+MySQL5.7.16
- src引入js时添加时间戳参数方法