how to design a login page in jsp? -
my index.jsp
consists of user name , password:
<html> <head> <title>employee page </title> </head> <body> <br> <p> <h3> <center>please enter user name , password</center> </h3> </p> <br> <br> <form action="login.jsp " method = "post" > <center>username</center> <center> <input type="text" name="username"> </center> <center>password</center> <center> <input type="pass" name="pass"> </center> <center> <input type="submit" name="submit" value="login" onclick="login.jsp" > </center> </form> </body> </html>
and following login.jsp
:
<html> <body bgcolor = "yellow"> <%@ page import ="java.sql.*" session = "false" %> <%! preparedstatement pst; connection con; public void jspinit() { try { driver mydriver = new oracle.jdbc.driver.oracledriver(); drivermanager.registerdriver(mydriver); connection con = drivermanager.getconnection("ashishga02","ea_dev","ea_dev"); pst = con.preparestatement("select username emp456 username = ? , pass = ? "); } catch(exception e) { } } public void jspdestroy() { try { con.close(); } catch(exception e) { } } %> <% string n = request.getparameter("username"); string p = request.getparameter("password"); pst.setstring(1,n); pst.setstring(2,p); resultset rs = pst.executequery(); if(rs.next()) { out.println("welcome"); } else { out.println("<font color = red> invalid ....</font>"); %> <%@ include file = "index.jsp"%> <% } %> </body> </html>
error stack-trace:
org.apache.jasper.jasperexception: exception occurred processing jsp page login.jsp @ line 40 37: <% 38: string n = request.getparameter("username"); 39: string p = request.getparameter("password"); 40: pst.setstring(1,n); 41: pst.setstring(2,p); 42: resultset rs = pst.executequery(); 43: if(rs.next()) stacktrace: org.apache.jasper.servlet.jspservletwrapper.handlejspexception(jspservletwrapper.ja org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:419) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:313) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:260) javax.servlet.http.httpservlet.service(httpservlet.java:717)
plese me this.
if wants alter whole code or query, free please @ least expalin code comments.
i knew in java not know anything. getting error on lines.