创建文件WEB-INF/test.properties:
#this is test myip
myip=192.168.7.8import javax.servlet.*;
...public class my class{
private static final String PROPFILE="/WEB-INF/test.properties";
PageContext pageContext;
Properties propfile;
...
public String readprop(){
String ls_propfile;
propfile = new Properties();
propfile.load(pageContext.getResourceAsStream(PROPFILE)); propfile = propfile.getProperty("myip");
return propfile;//属性返回值
}
}
#this is test myip
myip=192.168.7.8import javax.servlet.*;
...public class my class{
private static final String PROPFILE="/WEB-INF/test.properties";
PageContext pageContext;
Properties propfile;
...
public String readprop(){
String ls_propfile;
propfile = new Properties();
propfile.load(pageContext.getResourceAsStream(PROPFILE)); propfile = propfile.getProperty("myip");
return propfile;//属性返回值
}
}
解决方案 »
- arraylist<class>客户端服务器传递时ClassNotFound的问题
- Tomcat在reload时报错
- 关于FCK编辑后的内容脱html标签,达人帮下忙
- 大家好:编译类文件时报错,软件包 javax.servlet.http 不存在
- 关于hibernate的问题????????????????
- 使用包的servlet需要有什么特殊的配置么?
- 有关在jsp中调用word插件的问题。
- 用JAVAMAIL开发WEBMAIL接收邮件如何防止重复收取邮件?在线
- Apache2.0版本在httpd.conf中载入mod_jk.dll,为何总是提示“找不到指定的模块”
- java有什么办法可以对比两个字符串近似相等呢?
- 请问如何把jbuiler7和weblogic7整合起来.以便开发ejb.哪里有现成资料吗,谢谢大家!
- 怎么知道mysql使用什么中文编码方式(charsetEncoding)?或者说怎么设置中文编码方式?
你说的方法中java bean去调用PageContext,这个是javax.servlet.jsp.PageContext这个里的,一个java bean能调用jsp中的默认对象嘛?
e.g.
file application.properties exists in package 'resources'then ResourceBundle bundle = PropertyResourceBundle.getBundle("resources.application");
你在bean中写个方法,读取、处理文件的方法,可以传入文件名及路径!
在别的JSP中调用,那个JSP文件可以和WEB-inf文件夹之间发生联系吧,比如JSP文件和web-inf同级!
可以通过request.getRealPath()得到真实的地址,再传给bean
可以吗,如行,给我发短消息!