jsp配合java文件实现用户登录程序

21 篇文章 2 订阅
15 篇文章 0 订阅

Ulogin.jsp

<%@ page contentType="text/html; charset=utf-8" language="java"
	import="java.sql.*" errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
	<head>
		<meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-

scale=1">  
	    <title>用户登录</title>
        <meta name="description" content="">
        <meta name="author" content="templatemo">
        <!-- 
        Visual Admin Template
        http://www.templatemo.com/preview/templatemo_455_visual_admin
        -->
	    <link href='http://fonts.googleapis.com/css?family=Open

+Sans:400,300,400italic,700' rel='stylesheet' type='text/css'>
	    <link href="css/font-awesome.min.css" rel="stylesheet">
	    <link href="css/bootstrap.min.css" rel="stylesheet">
	    <link href="css/templatemo-style.css" rel="stylesheet">
	    
	    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements 

and media queries -->
	    <!-- WARNING: Respond.js doesn't work if you view the page via 

file:// -->
	    <!--[if lt IE 9]>
	      <script 

src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
	      <script 

src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
	    <![endif]-->
	<meta http-equiv="Content-Type" content="text/html; charset=utf-

8"><style type="text/css">
<!--
body {
	background-image: url(images/bg1.jpg);
}
body,td,th {
	color: #000;
}
.light-gray-bg b span .list-group a u {
	color: #000;
	text-align: right;
}
-->
    </style></head>
	<body class="light-gray-bg">
    <b style="font-family:verdana;text-align:right;color:#fff;font-

size:24px;">  <span style="text-align: right; color: #000; font-

size: 24;"> <span class="list-group"><a 

href="Glogin.jsp"><u>Rooter</u></a></span></span></b>
    <div class="templatemo-content-widget templatemo-login-widget white-bg">
<header class="text-center">
		    <h1>WELCOME YOU</h1>
	        </header>
	        <form method="post" action="ULogin" class="templatemo-login-

form">
	        	<div class="form-group">
	        		<div class="input-group">
		        		<div class="input-group-addon"><i 

class="fa fa-user fa-fw"></i></div>	        		
		              	<input name="username" type="text" 

class="form-control" placeholder="js@dashboard.com">           
		          	</div>	
	        	</div>
	        	<div class="form-group">
	        		<div class="input-group">
		        		<div class="input-group-addon"><i 

class="fa fa-key fa-fw"></i></div>	        		
		              	<input name="pwd" type="password" 

class="form-control" placeholder="******">           
		          	</div>	
	        	</div>	          	
	          	<div class="form-group">
				    <div class="checkbox squaredTwo">
				        <input type="checkbox" id="c1" 

name="cc" />
						<label 

for="c1"><span></span>Remember me</label>
				    </div>				    
				</div>
				<div class="form-group">
					<button type="submit" 

class="templatemo-blue-text width-100">Login</button>
				 </div>
	        </form>
		</div>
		<div class="templatemo-content-widget templatemo-login-widget 

templatemo-register-widget white-bg">
			<p>Not a registered user yet? <strong><a 

href="signup.jsp">Sign up now!</a></strong></p>
		</div>
	</body>
</html>


ULogin.java//监测用户登陆信息

package sever;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import meeting.DAOFactory;
import meeting.User;
import meeting.UserDAO;
import meeting.UserDAOSimple;
import meeting.DAO;
/**
 * Servlet implementation class ULogin
 */
@WebServlet("/ULogin")
public class ULogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ULogin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");

		String username = request.getParameter("username"); //获取用户输入的用户名
		String pwd = request.getParameter("pwd"); //获取用户输入的密码

System.out.println(username+"    "+pwd);
		String res = null;
		String forwardUrl = null;
		UserDAO ad=DAOFactory.getUserDAO();//利用DAO匹配数据库中的信息
		

		if (ad.isExistsInUser(username, pwd)){//若输入信息正确
			//System.out.println(ad.isExistsInUser(username, pwd));
			User username1=ad.getuser(username);
			request.setAttribute("username1",username1); 
			//response.sendRedirect("/Uindex.jsp");
			forwardUrl = "Uindex.jsp";
			res = "yes"; 
		} else {
			//System.out.println(ad.isExistsInUser(username, pwd));
			forwardUrl = "shibai.jsp";
			res = "no"; 
		}
		
		RequestDispatcher dispatcher = request.getRequestDispatcher(forwardUrl);
		dispatcher.forward(request, response); 
		return;
	}
	

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值