Using DBHelper to implement login functions in JSP pages

Source: Internet
Author: User

First we need to write a simple landing page login.jsp, and then submit the from form to the index.jsp page. In the index.jsp page through the DBHelper connection database to determine the account number and password, if the password is correct to display the login success.

The following is the landing page code

<base href= "<%=basePath%>" >

<title> Landing Page </title>


<body>

Submit user name password to index.jsp
<form action= "index.jsp" Name= "Form1" method= "POST" >
<div >
<a> user:</a><br> <input class= "YH" type= "text" value= "" name= "username"/><br>
<a> password:</a><br> <input class= "ma" type= "password" value= "" name= "password"/><br>
<input class= "DL1" type= "submit" value= "Login"/>
</div>
</form>
</body>

Here is the code for INDEX.JSP:

<%@ page language= "java" import= "java.util.*,dbhelper.*,java.sql.*" pageencoding= "UTF-8"%>
<%%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<base href= "<%=basePath%>" >

<title> Verification Page </title>


<body>
<%
String sql= "SELECT * from user WHERE username=? and password=? ";
String uid=request.getparameter ("UID");
String pwd=request.getparameter ("pwd");
Object[] Params=new object[]{uid,pwd};
ResultSet Rs=dbhelper.getresultset (Sql,params);
if (Rs.next ())
Out.print ("Login Successful");
Else
Out.print ("Login Failed");
Rs.close ();
%>
</body>

Then copy the DBHelper package to the SRC folder

Replace the user name and password in the DBHelper code with your MySQL database.
Then you can run it.
I run the results

Using DBHelper to implement login functions in JSP pages

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.