±Û¾´ÀÌ :¿ÀÁ¦¿¬ 2000³â 4¿ù 30ÀÏ 15:22:16
À¯Àú ÀÎÁõ ¼ºí¸´À» ¸¸µé°í ÀÖ½À´Ï´Ù. txt¸¦ DB·Î ¾²·Á°í Çϴµ¥ ¿¡·¯´Â ¾È¶ß´Âµ¥ ½ÇÇàÀº µÇÁö ¾Ê´Â±º¿ä.
¼Ò½º ÄÚµå ÷ºÎÇÕ´Ï´Ù. Á» µµ¿ÍÁÖ¼¼¿ä.
txtÆÄÀÏ¿¡¼ µ¥ÀÌÅÍ °¡Á®¿À´Â ºÎºÐÀ» »©¹ö¸®°í UserDB ½ºÆ®¸µ¿¡ À¯Àú Á¤º¸µéÀ» ³ÖÀ¸¸é Á¦´ë·Î ÀÛµ¿ÇÕ´Ï´Ù.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class Login extends HttpServlet {
String UserDB;
public void doGet( HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException {
FileInputStream fis = new FileInputStream("userdb.txt");
DataInputStream dis = new DataInputStream(fis);
BufferedReader myReader = new BufferedReader(new InputStreamReader(dis));
String userid = req.getParameter("UserID");
String password = req.getParameter("Password");
res.setContentType("text/html");
PrintWriter out = res.getWriter( );
HttpSession session = null;
if ( userid.equals( "" ) || password.equals( "" ) ) {
out.println( "<P><P><P><H2 ALIGN=CENTER><FONT color= blue>" + "Please insert" +
" ID and Password all ! " + "</FONT></H2>" );
out.close( );
return;
}
String UserLine = "";
String tempLine = "";
String tempID = "";
String tempPass = "";
while ((UserDB = myReader.readLine()) != null){
tempLine = new String(UserDB);
if (tempLine.startsWith(userid)){
UserLine = tempLine;
}
}
StringTokenizer st2 = new StringTokenizer (UserLine, "/");
if (st2.hasMoreTokens()){
tempID = st2.nextToken();
if(st2.hasMoreTokens()){
tempPass = st2.nextToken();
}
}
out.println("<html><head><title>User Login</title></head><body>");
out.println("<P><P><P><H1>"+ UserLine +"<H1>");
out.println("<P><P><P><H1>" + password + "</H1>");
if (password.equals(tempPass)) {
out.println("<p><p><p><H1 Align=Center><Font color =blue>" + "Login Success!" + "</Font></H1>");
}
else {
out.println( "<P><P><P><H1 ALIGN=CENTER><FONT color=#820060>" + "Log in fail ! " + "</FONT></H1>");
out.println("<P><P><P><H2 ALIGN = CENTER><FONT color=#135A9E>" + "Please insert your ID and Password" +
" strictly ! " + "</FONT></H2>" );
}
out.println("</body></html>");
out.close( );
}
}