Verify and connect to the database on the Jsp login page and the front and back ends

Source: Internet
Author: User

Bkjia.com JSP documentThe front login.html page and the back-end verifylogin. jsp page are composed:
Login.html content:

Reference content is as follows:

<Html>
<Head>
<Title> logon </title>

<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8">
<Meta http-equiv = "Content-Language" content = "ch-cn">
</Head>

<Body>
<! -- Form is used to extract information entered and submitted by users -->
<Form method = "post" name = "frmLogin" action = "verifylogin. jsp">
<H1 align = "center"> User Logon <Div align = "center"> User Name:
<Input type = "text" name = "txtUserName" value = "Your name"
Onfocus = "if (this. value = 'your name') this. value =''; "> <br> password:
<Input type = "password" name = "txtPassword" value = "Your password"
Onfocus = "if (this. value = 'your password') this. value =''; "> <br>
<Input type = "submit" name = "Submit" value = "submit"> & nbsp;
<Input type = "reset" name = "Reset" value = "reset"> <br>
</Div> </form> </body>
</Html>

Verifylogin. jsp content:
<% @ Page language = "java" contentType = "text/html; charset = gb2312"
PageEncoding = "UTF-8" %>

<% @ Page import = "java. SQL. *" %>
<% @ Page import = "java. util. *" %>


<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> logon </title>

<Meta http-equiv = "pragma" content = "no-cache">
<Meta http-equiv = "cache-control" content = "no-cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "This is my page">
<! --
<Link rel = "stylesheet" type = "text/css" href = "styles.css">
-->

</Head>

<Body>
<Div align = center>
<%
// Obtain the user name
String sUserName = request. getParameter ("txtUserName ");
// Obtain the password
String sPasswd = request. getParameter ("txtPassword ");

// Register the JDBC driver
Class. forName ("org. gjt. mm. mysql. Driver"). newInstance ();
// The Connection parameters are different from the Access parameters.
String url = "jdbc: mysql: // localhost/LearnJSP ";
// Establish a connection
Connection connection = DriverManager. getConnection (url, "root ",
"011124 ");
// SQL statement
String SQL = "select * from userinfo where username = '" + sUserName
+ "'And userpwd ='" + sPasswd + "'";

Statement stmt = connection. createStatement ();
ResultSet rs = stmt.exe cuteQuery (SQL); // return the query result

// If the record set is not empty, it indicates that a matched user name and password exist and the logon is successful.
If (rs. next ())
{
Out. println ("Logon successful! ");
} Else
// Otherwise, the logon fails.
{
Out. println ("the user name does not exist or the password is incorrect! ");
}

Rs. close ();
Stmt. close ();
Connection. close ();
%>
</Body>
</Html>

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next Page

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.