*.properties放在哪里呀???
我建了一个虚拟目录test
Servlet文件如下:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class test extends HttpServlet
{
private static Properties http_props = new Properties();
private static String zwd;
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
try
{
FileInputStream infile =new FileInputStream("test.properties");
http_props.load(infile);
zwd = http_props.getProperty("zwd");
infile.close();
}
catch (Exception e)
{
System.out.println(e);
return;
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
String zwd_d=zwd;
PrintWriter outhtml=res.getWriter();
res.setContentType("text/html");
outhtml.println ("<html><body><center>");
outhtml.println ("AAA="+zwd_d);
outhtml.println ("</center></body></html>");
}
}
我将test.class放到了Web-Info的class里面,
test.properties文件如下:
zwd=abcedfghigk
我将test.properties放到了Web-Info的class里面,
可是运行tomcat,出现如下错误:
java.io.FileNotFoundException:test.properties<系统找不到指定文件。>
到底放到哪里呀???
晕了!!
问题点数:40、回复次数:8Top
1 楼wizard0128(wizard)回复于 2003-12-03 00:22:28 得分 0
FileInputStream infile =new FileInputStream("test.properties");
放在 WEB-INF/classes/test.properties
Top
2 楼wizard0128(wizard)回复于 2003-12-03 00:22:53 得分 0
还有 注意大小写Top
3 楼eureka0891(迷茫中...)回复于 2003-12-03 08:06:49 得分 0
也可指定路径Top
4 楼woxinyongheng(枚枚)回复于 2003-12-03 10:21:04 得分 0
把test.properties 文件放入bin目录下Top
5 楼gao277(流氓状元)回复于 2003-12-03 10:37:49 得分 40
路径不要变,代码改成如下试试:
InputStream in = this.getClass().getResourceAsStream("/test.properties");
http_props.load(in);Top
6 楼allan1031(加西亚想睡觉)回复于 2003-12-03 15:00:48 得分 0
如果你是TOMCAT的话,照你的代码,应该放在tomcat的安装目录下
Top
7 楼zwd2878(安东)回复于 2003-12-03 18:22:40 得分 0
gao277(流氓状元)
多谢大哥:)
问题解决了:)
太感谢了:)Top
8 楼zwd2878(安东)回复于 2003-12-03 18:58:43 得分 0
还想问问,为什么我的那个不行那:)Top




