jsp页面的使用
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//1.获取资源文件
InputStream is=this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");
String value="aaaa";
this.getServletContext().setAttribute("data", value);
request.setAttribute("value", value);
this.getServletContext().getRequestDispatcher("/1.jsp").forward(request, response);
}
1.jsp
<body>
<%
String value = (String) request.getAttribute("value");
String data = (String) application.getAttribute("data");
out.write("data:" + data);
out.write("value:" + value);
%>
This is my JSP page.
<br>
</body>
</html>
获取配置文件
InputStream is = this.getServletContext().getResourceAsStream( "/WEB-INF/classes/db.properties");
Properties prop = new Properties(); prop.load(is);
String url = prop.getProperty("dburl");
String username = prop.getProperty("username");
String password = prop.getProperty("password");
System.out.println(url + " " + username + " " + password);
//获取硬盘上的实际路径
String db = this.getServletContext().getRealPath("/WEB-INF/classes/db.properties");
最新文章
- [翻译]AKKA笔记 - DEATHWATCH -7
- Java 如何跳出多重嵌套循环体?
- Mob.com 短信验证的简单使用
- android studio 注释模板
- GC是什么? 为什么要有GC?
- XAF应用开发教程(七)外观控制模块
- java线程实践记录
- UVa 400 (水题) Unix ls
- Python爬虫学习:四、headers和data的获取
- 【转】commons-fileupload-1.2.1.jar和commons-io-1.3.2.jar实现文件上传
- zoj 3708 Density of Power Network
- python编程基础知识—列表(二)
- CentOS7卸载自带jdk安装自己的JDK1.8
- day 05字典相关内容
- 用Python对html进行编码
- laravel简书(2)
- jdk8 tomcat7
- 使用Beetle简单构建聊天室程序
- mysql不能启动报error2013错误的解决办法
- EF4.1 企业架构模式 自动映射数据表(转载)
热门文章
- caffe: compile error : undefined reference to `cv::imread(cv::String const&;, int)&#39; et al.
- ascii codec can&#39;t decode byte 0xe8 in position 0:ordinal not in range(128)
- Cannot unwrap to requested type [javax.sql.DataSource]
- linux服务之openldap
- linux包之e2fsprogs之chattr命令
- wamp下Apache2.4.x局域网访问403的解决办法
- Python 2.x与3.x共存
- Reporting Service 报表报 rsReportServerDatabaseError 错的解决方法
- openstack(liberty): devstack之screen
- CCS float vs clear