Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 11th, 2003, 11:50 PM
Registered User
 
Join Date: Jul 2003
Location: colchester, essex, United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default JSP and LOGIN

Anyone could help me how can i create a login page by jsp....
it need to check username = password from database
 if u forget password it remind you your secret question and answer...THANKS


  #2 (permalink)  
Old April 28th, 2005, 01:35 AM
Registered User
 
Join Date: Feb 2005
Location: ShangHai, , China.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<%
String username=request.getParameter("username");
String userpass=request.getParameter("userpass");
String DBDriver="jdbc:odbc:driver={Micosoft Access Driver(*.mdb)";
try{
    Connection conn=null;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn=DriverManager.getConnection(DBDriver);
    Statement comm=conn.createStatement();
    String strSQL = "select * from member where username='"+username+"' and userpass='"+userpass+"'";
    ResultSet Res=comm.executeQuery();
    if(!Res.next()){
        out.println("<script>alert('error information');</script>");
    }else{
        out.println("welcome"+username+"!");
    }
}catch(Exception ex){
    out.println("Error:"+ex.getMessage());
}finally{
    Res.close();
    conn.close();
}
%>

  #3 (permalink)  
Old April 29th, 2005, 12:08 AM
Authorized User
 
Join Date: Mar 2005
Location: Pune, Maharashtra, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dadahonde Send a message via Yahoo to dadahonde
Default

Hello You are right on the way.
Except following is the little mistake i noticed in the piece of code you prepared.
For reference your statement is :
      ResultSet Res=comm.executeQuery();
You need to pass the parameter which is a SQL query(String) to the executeQuery() method.

so the statement would become as :
     ResultSet Res=comm.executeQuery(strSQL);


Regards
Dadasaheb T. Honde


  #4 (permalink)  
Old November 30th, 2005, 04:11 AM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have modify the code that peter huang wrote and try to run .. but erro occur .. can anyone helps me?

[u]admin_login.jsp</u>
<%@ page import="java.sql.*" %>

<%
    String adminId = request.getParameter("admin_id");
    String adminPassword = request.getParameter("admin_password");
    String driver = "jdbc:mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/sers";
    String username = "root";
    String password = "123";
    String query = "SELECT admin_id,admin_password FROM admin WHERE admin_id = '"+adminId+"' AND admin_password = '"+adminPassword+"'";
    Connection con = null;
    Statement statement = null;
    ResultSet rs = null;

    try
    {
        Class.forName(driver);
        con = DriverManager.getConnection(url,username,password) ;
        statement = con.createStatement();
        rs = statement.executeQuery(query);
        if(!rs.next())
        {
            out.println("<h1>Login Fail</h2>");
        }
        else
        {
            out.println("<h1>welcome" + "!</h1>");
        }
    }
    catch(Exception ex)
    {
        out.println("Error: " + ex.getMessage());
    }
    finally
    {
        rs.close();
        con.close();
    }
%>



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! JSP Login yikchin JSP Basics 1 December 8th, 2005 02:35 AM
jsp login page ronnie JSP Basics 4 April 12th, 2005 11:45 PM
jsp & mysql login code sos jaymak121 Java Databases 4 November 25th, 2004 06:50 AM
Help with jsp login page javaStudent JSP Basics 0 January 27th, 2004 06:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.