Java Web login Interface source code

Source: Internet
Author: User
Tags java web

Approximate process:

to import sqljdbc4 packages in a Java Web project

to complete java code in Java Resources

Create a folder to write your own jsp under WebContent

Paste the sqljdbc4 and jstl-1.2 packages under the lib file under web-inf file .

Java Web Login Interface source code :

1.data_uil.java

ImportJava.sql.*; Public classData_uil { PublicConnection getconnection () {Try{class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver"); }Catch(ClassNotFoundException e) {e.printstacktrace (); } String User="***"; String Password="***"; String URL= "jdbc:sqlserver://127.0.0.1:1433;databasename=***"; Connection Con=NULL; Try{con=drivermanager.getconnection (Url,user,password); }Catch(SQLException e) {e.printstacktrace (); }        returncon; }     Publicstring Selectpassword (string username) {Connection Connection=getconnection (); String SQL= "Select *from login where Username=?"; PreparedStatement PreparedStatement=NULL; ResultSet result=NULL; String Password=NULL; Try{PreparedStatement=connection.preparestatement (SQL); Preparedstatement.setstring (1, username); Result=preparedstatement.executequery ();//an executable query            if(Result.next ()) Password=result.getstring ("Password"); }Catch(SQLException e) {e.printstacktrace (); }finally{Close (PreparedStatement);            Close (result);        Close (connection); } System.out.println ("The database password found is:" +password); returnpassword; }     Public  voidClose (Connection con) {Try{            if(con!=NULL) {con.close (); }        }Catch(SQLException e) {e.printstacktrace (); }    }     Public  voidClose (PreparedStatement preparedstatement) {Try{            if(preparedstatement!=NULL) {preparedstatement.close (); }        }Catch(SQLException e) {e.printstacktrace (); }    }     Public  voidClose (ResultSet ResultSet) {Try{            if(resultset!=NULL) {resultset.close (); }        }Catch(SQLException e) {e.printstacktrace (); }    }}

2.LOGIN_CHECK.JSP:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "Utf-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >class= "util." Data_uil "scope=" page "/><%String username= (String) request.getparameter ("username"); String Password= (String) request.getparameter ("Password"); if(username==NULL||"". Equals (username)) {Out.print ("<script language= ' JavaScript ' > alert (' User name cannot be null ');</script>"); Response.setheader ("Refresh", "0;url=user_login.jsp"); }    Else{System.out.println ("User name entered:" +username); String Passwordindatabase=Util.selectpassword (username); System.out.println ("Password:" +passwordindatabase); if(passwordindatabase==NULL||"". Equals (Passwordindatabase)) {Out.print ("<script language= ' JavaScript ' > alert (' User name does not exist ');</script>"); Response.setheader ("Refresh", "0;url=user_login.jsp"); }        Else if(passwordindatabase.equals (password)) {Out.print ("<script language= ' JavaScript ' > alert (' Login successful ');</script>"); Response.setheader ("Refresh", "0;url=loginsucces.jsp"); }        Else{out.print ("<script language= ' JavaScript ' > alert (' Password error ');</script>"); Response.setheader ("Refresh", "0;url=user_login.jsp"); }    }%></body>

3.loginsucces.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" Utf-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

4.user_login.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "Utf-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Operation Result:

Java Web login Interface source code

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.