Hi all , I have a servlet program, this program will get a user name and password from a web page. I need to check the user name and passsword entered by user with a data file has all user names and passwords. the thing is I know how to search and check if the name and password in data file or not . my problem is my servlet shows a message to me says


"description The server encountered an internal error () that prevented it from fulfilling this request.

java.io.FileNotFoundException: admin.txt (The system cannot find the file specified)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(FileInputStream.java:106)
java.io.FileReader.<init>(FileReader.java:55)
InputServlet.doGet(InputServlet.java:15)
InputServlet.doPost(InputServlet.java:69)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:420)
org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.
Apache Tomcat/5.5.27


although I have put the compiled program with the file under Classes directory, I get the same error

and I have tried to put the program + its class + the file , under Classes Directory , I get the same error (exception)


please help!

when you post the error , please post your code

this is my code

import java.io.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
   public class InputServlet extends HttpServlet
   {
         public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException, ServletException, FileNotFoundException
          {
                     File Admin = new File("admin.txt");
                   
                   
                   
                    FileReader reader = new FileReader(Admin);
                     BufferedReader in = new BufferedReader(reader);
                     
                     String name = request.getParameter("Name");
                     String p = request.getParameter("password");
                     int password = Integer.parseInt(p);
                     
                     String line;
                     String array[]; 
                     line = in.readLine();
                     while(line != null)
                     {
                     	array = line.split("\t");
                        int filePassword = Integer.parseInt(array[1]);
                        
                        if(array[0].equals(name)  &&  filePassword == password)
                        {
                        	 response.setContentType("text/html");
                             PrintWriter out = response.getWriter();
                             out.println("<html>");
                             out.println("<head>");
                             out.println("<title>Input Servlet</title>");
                             out.println("</head>");
                             out.println("<body>");
                             out.println("<h1>");
                             out.println("Hello " + name); 
                             out.println("</h1>");
                             out.println("</body>");
                             out.println("</html>");
                             in.close();
                             break;
                        }
                        else
                        {
                              response.setContentType("text/html");
                             PrintWriter out = response.getWriter();
                             out.println("<html>");
                             out.println("<head>");
                             out.println("<title>Input Servlet</title>");
                             out.println("</head>");
                             out.println("<body>");
                             out.println("<h1>");
                             out.println("Sorry wrong Login entered!"); 
                             out.println("</h1>");
                             out.println("</body>");
                             out.println("</html>");
                             in.close();
                             break;	
                        }
                     }
                     
                     
         }
         public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException, ServletException
         {
                    doGet(request, response);
         }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.