import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class login extends HttpServlet{
	Connection cn;
	String user, pass;
	boolean yhendus=false;
	
	public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException{
		PrintWriter valja = vastus.getWriter();
		user=kysimus.getParameter("u");
		pass=kysimus.getParameter("p");
			if(user!=null && pass!=null && user.length()!=0 && pass.length()!=0){
				try{
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
					cn=DriverManager.getConnection("jdbc:odbc:plaadikogu", user, pass);
					if(cn.isClosed()==false){yhendus=true;}
				}catch(Exception e){valja.println("Tekkis viga: "+e);}
			}
			if(yhendus==false){
				valja.println("<html><head><title>.o0|SISENEMINE|0o.</title></head><body><center><h2>Sisenemine</h2></center><br/>");
				valja.println("<form><table align='center'>");
				valja.println("<tr><td>Kasutajanimi:</td><td><input type='text' name='u'></td></tr>");
				valja.println("<tr><td>Parool:</td><td><input type='text' name='p'></td></tr>");
				valja.println("<tr><td><input type='submit' value='SISENE'></td></tr></table></form>");
				valja.println("</body></html>");
			}else{
				valja.println("<html><head><title>.o0|TEGEVUSE VALIK|0o.</title></head><body><center><h2>Vali tegevus</h2></center><br/>");
				valja.println("<center><table>");
				valja.println("<tr><td align='center'><a href='kuvaja?u="+user+"&p="+pass+"'>.::Vaata andmeid::.</a></td></tr>");
				valja.println("<tr><td align='center'><a href='looLisaja?u="+user+"&p="+pass+"'>.::Lisa/Muuda andmeid::.</a></td></tr>");
				valja.println("<tr><td align='center'><a href='xml?u="+user+"&p="+pass+"'>.::Andmebaasi backup::.</a></td></tr>");
				valja.println("</table></center></body></html>");
				try{
					if(cn.isClosed()==false){cn.close();}
				}catch(Exception e){valja.println("Tekkis viga: "+e);}
			}
	}
}			