登录界面
Posted 20153143
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了登录界面相关的知识,希望对你有一定的参考价值。
连接数据库
import java.sql.*;
public class Main {
public static void main(String [] args)
{
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=qwer";
String userName="sa";
String userPwd="829727";
try
{
Class.forName(driverName);
System.out.println("加载驱动成功!");
}catch(Exception e){
e.printStackTrace();
System.out.println("加载驱动失败!");
}
try{
Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("连接数据库成功!");
}catch(Exception e)
{
e.printStackTrace();
System.out.print("SQL Server连接失败!");
}
}
}
登录界面
<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>登录界面</title>
</head>
<body >
<center>
<h2>登录界面</h2>
<form action="lianjie.jsp" method="post">
用户:<input type="text" name = "usern ame"><br>
密码:<input type="password" name="password"><br>
<input type="submit" value="提交">
</form>
</center>
</body>
</html>
登录
<%@ page language="java" import="java.sql.*" import="java.util.*" 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录</title>
</head>
<body>
<%
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=qwer";
String userName="sa";
String userPwd="829727";
Class.forName(driverName);
Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
String sql = "select * from Table_1 where [name]=? and [password]=?";
PreparedStatement pstmt = dbConn.prepareStatement(sql);
request.setCharacterEncoding("UTF-8");
String user = request.getParameter("username");
String pass = request.getParameter("password");
pstmt.setString(1, user);
pstmt.setString(2, pass);
ResultSet rs = pstmt.executeQuery();
if(rs.next()) {
%><center><h1>登陆成功!</h1></center><%
}
else
{
%><center><h1>登陆失败!</h1></center><%
}
%>
</body>
<ml>
以上是关于登录界面的主要内容,如果未能解决你的问题,请参考以下文章