输入输出的一个错误

ncist_jianeng 2011-10-20 07:53:33
我写的一个servlet
运行时抛出的是input Error。那应该是被IOException接收到了,但不知道是错在哪????


package DengRu;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DengRuServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
try{
String zhanghao=request.getParameter("zhanghao");
String mima=request.getParameter("mima");

FileReader file=new FileReader("zhanghao.txt");
BufferedReader fileread=new BufferedReader(file);

String mima1=fileread.readLine();
String zhanghao1=fileread.readLine();
file.close();
fileread.close();
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
if(zhanghao.equals(zhanghao1)&&mima.equals(mima1)){
//response.sendRedirect("liuyanban.html");
out.println("</html><body>");
out.println(zhanghao+mima);
out.println("</body></html>");
}else{
//response.sendRedirect("denglujiemian.html");
out.println("</html><body>");
out.println("登录失败");
out.println("</body></html>");
}
}catch(IOException e){
log("input Error");
}catch(Exception e){
log("qi ta cuo wu");
}
}
}
...全文
62 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ncist_jianeng 2011-10-20
  • 打赏
  • 举报
回复
弄好了,谢谢你的回答
xiaohao_code 2011-10-20
  • 打赏
  • 举报
回复
楼上说的很对哦,建的web项目,配置到服务器以后不会出现这个路径的……
幽饮烛 2011-10-20
  • 打赏
  • 举报
回复
!!!你是怎么运行的,在网站上运行时不会输出这个路径的。
ncist_jianeng 2011-10-20
  • 打赏
  • 举报
回复
它输出的是C:\programs\workplase\GeRenWangZhan

我也是放在这个目录下的。在应用程序中可以运行。。。。。。用网站运行时就出现上面的错误。。。郁闷
幽饮烛 2011-10-20
  • 打赏
  • 举报
回复
你在 doPost 中加入一行 System.out.println(new File("").getAbsolutePath());
看一下输出的路径就知道了。
ncist_jianeng 2011-10-20
  • 打赏
  • 举报
回复
有这个文件的,我用的是myeclipse开发。我当初也这么想,可是当我将它改写成应用程序时是可以正常运行的。再问一句,那我这个文件应该放在什么位置
幽饮烛 2011-10-20
  • 打赏
  • 举报
回复
java.io.FileNotFoundException: zhanghao.txt (系统找不到指定的文件。)

没有这个文件。。。。。。。zhanghao.txt
ncist_jianeng 2011-10-20
  • 打赏
  • 举报
回复
变成java.io.FileNotFoundException: zhanghao.txt (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:41)
at DengRu.DengRuServlet.doPost(DengRuServlet.java:21)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
幽饮烛 2011-10-20
  • 打赏
  • 举报
回复
呃,把 log("input Error"); 改成 e.printStackTrace(); 再看看是哪一行报错。
ncist_jianeng 2011-10-20
  • 打赏
  • 举报
回复
可不可以具体点呀?
幽饮烛 2011-10-20
  • 打赏
  • 举报
回复
直接调试。。。

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧