eclipse servlet简单的用户登录


servlet程序

package test;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class first_servlet
 */
@WebServlet("/first_servlet")
public class first_servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public first_servlet() {
        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
		String name=request.getParameter("inputname");
		String pwd=request.getParameter("inputpwd");
		if(name!=null&&name.equals("martin")) {
			response.sendRedirect("http://blog.csdn.net/martind");
		}else {
			response.sendRedirect("https://www.baidu.com");
		}
		
	}

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

}


登录界面
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>my first bootstrap</title>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet"
	href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
	integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
	crossorigin="anonymous">
<link rel="stylesheet"
	href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
	integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
	crossorigin="anonymous">
<script
	src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"
	integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
	crossorigin="anonymous"></script>
</head>

<body>
	<div class="container">
		<h1 class="page-header  col-md-offset-4">用户登录</h1>
		<form action="first" method="post" class="form-horizontal">
		
			<div class="form-group">
				<label for="inputname" class="col-md-4 control-label">用户名
					 <span class="glyphicon glyphicon-user"></span>
				</label>
				<div class="col-md-4">
					<input type="text" class="form-control" name="inputname"
						placeholder="请输入用户名" />
				</div>
			</div>
			<div class="form-group">
				<label for="inputpwd" class="col-md-4 control-label">密码
					 <span class="glyphicon glyphicon-lock"></span>
				</label>
				<div class="col-md-4">
					<input type="password" class="form-control" name="inputpwd"
						placeholder="请输入密码" />
				</div>
			</div>
			<div class="form-group">
				<div class="col-md-offset-5">
					<button class="btn btn-primary">注册</button>
					<button class="btn btn-primary">登录</button>
				</div>
			</div>
			
		</form>
	</div>
</body>

</html>


xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
   <servlet>
    <servlet-name>first_servlet</servlet-name>
    <servlet-class>test.first_servlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>first_servlet</servlet-name>
    <url-pattern>/first</url-pattern>
  </servlet-mapping>
</web-app>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值