Simple Java Web Implementation interface development

Source: Internet
Author: User

A simple login interface for Javaweb development the tools used here are eclipse, SQL 2016, tomcat8

Before development, you need to complete the connection configuration of Tomcat and SQL in Eclipse, where Tomcat starts automatically when the Web project runs, and the development steps are described below

First, the establishment of Web projects

Open Eclipse Point solution file->new->dynamic Web Project

Enter the project name by entering the following interface

Click Next

Then click Next to go to the next screen

Select the location where the arrows point, click Finish, and complete the creation of the Web project

Third, database Building table

Open database Right-click Database New Database

Click New Database, right click on table--new table

Enter a column name here, select a good data type

Enter information after opening

Save and complete the database table establishment

Iv. Database Connection

Drag the Sqljdbc4.jar file into the Web-inf

V. Add a JSP file

Right-click WebContent

Finish completing the JSP file creation

Enter the following code when the creation is complete

<%@ 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" >User: <input type= "text" name = "username" ><br> password: <input type= "password" name= "pass" ><br> <input type= "Submit" value= "Login" ></form></center></body>

Run, can complete the creation of the interface

Enter the code

<%@ page language= "Java"Import= "java.sql.*" 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" >String drivername= "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; String Dburl= "Jdbc:sqlserver://localhost:1433;databasename=hh"; String UserName= "SA";//Database login account password String userpwd= "g15034014195";    Class.forName (drivername); Connection Dbconn=drivermanager.getconnection (DBURL,USERNAME,USERPWD); String SQL= "SELECT * from log where [user]=? And [pass]=?]//user Pass represents the column name created in the database
PreparedStatement pstmt=dbconn.preparestatement (SQL); Request.setcharacterencoding ("UTF-8");
String User= Request.getparameter ("username");
String Pass= Request.getparameter ("Pass"); Pstmt.setstring (1, user);
Pstmt.setstring (2, pass);
ResultSet RS=Pstmt.executequery ();
if(Rs.next ()) {%><center> } Else { %><center> } %> </body>

The operation results are as follows

Simple Java Web Implementation interface development

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.