i didnt get the correct ANSWER PLZ EXECUTE THE FOOLWING SERVLET BY USING DATABASE USERLOGIN TABLE VALUES. //validate login.html <html> <body> <body bgcolor="wheat"> <center> <h1>Login Form</h1> <form action="ss"> <Table> <tr> <td>enter name</td> <td><Input Type="text" name="uname"></td> </tr> <tr> <td>enter password</td> <td><Input Type="password" name="pwd"></td> </tr> <tr> <td><Input type="CHECKBOX" value="tick">remember my password</td> </tr> <tr> <td><Input type="submit" value="submit"></td> </tr> <tr> <td><Input type="reset" value="clear"></td> </tr> </Table> </form> </center> </body> </html> //vallidate user n pwd by validservlet package active; import javax.servlet.*; import java.io.*; import java.sql.*; public class validservlet extends GenericServlet { Connection conn; ServletConfig sc; ServletContext scont; public void init() throws ServletException { try{ sc=getServletConfig(); scont=sc.getServletContext(); String driver=scont.getInitParameter("driver"); String url=scont.getInitParameter("url"); String user=sc.getInitParameter("User"); String Password=sc.getInitParameter("Password"); Class.forName(driver); conn=DriverManager.getConnection(url,user,Password); } catch(Exception e) { System.out.println(e.getMessage()); } } public void service(ServletRequest req, ServletResponse res) throws IOException,ServletException { res.setContentType("text/html"); PrintWriter out=res.getWriter(); try{ String uname=req.getParameter("uname"); String pwd=req.getParameter("pwd"); String sql="SELECT * FROM userlogin UNAME=? and PWD=?"; PreparedStatement pst=conn.prepareStatement(sql); pst.setString(1,uname); pst.setString(2,pwd); ResultSet rs=pst.executeQuery(); if(rs.next()) { RequestDispatcher rd=req.getRequestDispatcher("Admin.java"); rd.forward(req,res); } else { RequestDispatcher rd=req.getRequestDispatcher("userlogin.html"); //rd.forward(req,res); rd.include(req,res); System.out.println("<center><font color=red>invalid</font></center>"); } } catch(Exception e){} } public void destroy() { try {conn.close(); }catch(Exception e){} } } package active; import javax.servlet.*; import java.io.*; import java.sql.*; public class Admin extends GenericServlet { public void service(ServletRequest req,ServletResponse res)throws IOException,ServletException { res.setContentType("text/html"); PrintWriter out=res.getWriter(); System.out.println("<center> welcome to Admin </center>"); } } <web-app> <content-param> <param-name>driver</param-name> <param-value> sun.jdbc.odbc.JdbcOdbcDriver </param-value> </content-param> <content-param> <param-name>url</param-name> <param-value> jdbc:odbc:mydsn </param-value> </content-param> <servlet> <servlet-name>validservlet</servlet-name> <servlet-class>active.validservlet</servlet-class> <init-param> <param-name>user</param-name> <param-value>system</param-value> </init-param> <init-param> <param-name>password</param-name> <param-value>rammohan</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>validservlet</servlet-name> <url-pattern>/ss</url-pattern> </servlet-mapping> <servlet> <servlet-name>Admin</servlet-name> <servlet-class>active.Admin</servlet-class> </servlet> <servlet-mapping> <servlet-name>Admin</servlet-name> <url-pattern>/admin</url-pattern> </servlet-mapping> </web-app>
Hello,
If you are using init parameters(for username and password) to check from database whether they are valid or not then what is the need of html to insert the values of username and password?
Please clarify this.
Hi,
Actually i want to write the program for validate the username and password through database.
My idea is to write the programe whenever user want to see the his information he should enter to his account through html,if user and password is valid then get the information from database.......
And that init parameter belongs to database.....
sorry that init parameters belongs to connction object which is taking arguments url,user,password