import java.sql.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class ident extends HttpServlet{ public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus)throws IOException, ServletException{ doPost(kysimus, vastus); } public void doPost(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException{ String kasutajanimi=kysimus.getParameter("login"); String parool=kysimus.getParameter("pass"); HttpSession sessioon=kysimus.getSession(); vastus.addHeader("Location: ", "http://localhost:8080/examples/login.html"); // return; // vastus.setContentType("text/html"); PrintWriter valja=new PrintWriter(vastus.getWriter()); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn= DriverManager.getConnection("jdbc:odbc:kasutajatebaas", "", ""); Statement st=cn.createStatement(); String otsi="SELECT user,password FROM Table1 where user='"+kasutajanimi+"';"; ResultSet rs=st.executeQuery(otsi); boolean kasOn=rs.next(); if (!kasOn){ valja.println("Sinu nime baasis pole!"); return; } String user=rs.getString("user"); String password=rs.getString("password"); if ((kasutajanimi.equals(user)) && parool.equals(password)){ sessioon.setAttribute("User",user); sessioon.setAttribute("Password",password); // vastus.addHeader("Location:", "http://localhost:8080/examples/login.html"); valja.println(""); System.out.println("Saadeti edasi"); }else{ valja.println("Sisselogimine ebaġnnestus!"); cn.close(); } }catch(Exception viga){ valja.println("Ilmnes viga andmebaasiga! " + viga); viga.printStackTrace(); } } }