import java.sql.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Foorumlogin extends HttpServlet{ public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus)throws IOException, ServletException{ HttpSession hs=kysimus.getSession(); String name=kysimus.getParameter("nimi"); String sona=kysimus.getParameter("salasona"); hs.setAttribute("nimi", name); vastus.setContentType("text/html"); PrintWriter valja=new PrintWriter(vastus.getWriter()); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn= DriverManager.getConnection("jdbc:odbc:king", "", ""); Statement st=cn.createStatement(); String onkasutaja="SELECT nimi,password FROM Kasutajad;"; ResultSet rs=st.executeQuery(onkasutaja); String nickname=""; Object password=""; int a = 0; while (rs.next()){ nickname=rs.getString("nimi"); password=rs.getString("password"); if(nickname.equals(name) && (password.equals(sona))){ a = a + 1; } if(nickname.equals(name) && (!password.equals(sona))){ a = a + 2; } } if (a == 1) { System.out.println(a); valja.println( "Foorum\n"+ "
"+ "Kasutaja "+name+ "
"+ "
"+ "
"+ ""+ ""+ "
"+ ""+ "
Tekst
"+ "
"+ "
"+ ""+ ""+ "
"+ "
"+ "" ); } if (a == 0){ System.out.println(a); valja.println( "\n"+ ""+ "
"+ "Kahjuks on kasutajanimi ja pareool valed!"+ "
"+ "Kui Te pole registreerunud, siis registreeruda saate siin "+ "registreeru"+ "" ); } if (a == 2){ System.out.println(a); valja.println( "\n"+ ""+ "
"+ "Kahjuks on parool vale!"+ "
"+ "Palun proovige "+ "uuesti."+ "" ); } cn.close(); }catch(Exception viga){ valja.println("Probleem andmebaasiga: "+viga); } } }