你是java的新手,所以面对一些问题,我从一个html页面调用servlet,它从不同的类调用不同的方法,但是从servlet执行类的方法时,它抛出的文件没有找到异常。但是一切存在于正确的道路上。虽然分别运行类的方法,但它的工作正常,但是从servlet开始它不是
SEVERE: Servlet.service() for servlet [Search] in context with path [/AutomationTest] threw exception
java.io.FileNotFoundException: WebContent\prop\html.txt (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at com.helix.etl.automation.dao.test.read(test.java:24)
at com.helix.etl.automation.controller.Search.doGet(Search.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
my test.java
public class test {
//String filenaame="WebContent/prop/html.txt";
/*public static void main(String[] args) throws IOException{
test t= new test();
t.read(filenaame);
}*/
String line="";
public List<String> read(String filename) throws IOException
{
File file =new File(filename);
FileReader fi = new FileReader(file);
BufferedReader in = new BufferedReader(fi);
List<String> tokens = new ArrayList<String>();
while((line=in.readLine())!=null){
tokens.add(line);
System.out.println("entering");
}
return tokens;
}
我的servlet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String Filename="WebContent/prop/html.txt";
test t = new test();
List<String> line=t.read(Filename);
for (String s : line) {
System.out.println(s);
out.print(s);}
}