1.注册页面

 <%@ 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=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="../js/jquery.validate.js"></script>
<script type="text/javascript">
$(function()
{
$("form").validate(); })
</script>
</head>
<body>
<form action="../Servlet" method="post">
用户名:<input type="text" name="userName" required /><br/>
密码:<input type="password" name="password" id="l1" maxlength="10" minlength="6" required /><br/>
确认密码:<input type="password" name="password" equalTo="#l1" required /><br/>
性别:<input type="radio" name="sex" required />男
<input type="radio" name="sex"/>女<br/>
出生日期:<input type="date" name="birthday" required /><br/>
个人爱好:<input type="checkbox" name="hobby" required />游泳
<input type="checkbox" name="hobby"/>篮球
<input type="checkbox" name="hobby"/>排球
<input type="checkbox" name="hobby"/>气球<br/>
<button type="submit">注册</button>
<button type="reset">重置</button>
</form>
</body>
</html>

2.servlet

 package com.zdsofe.servlet1;

 import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement; 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 Servlet
*/
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static String DRIVER="com.mysql.jdbc.Driver";
private static String URL="jdbc:mysql://localhost:3306/mysql";
private static String user="root";
private static String key="775297";
Connection conn;
int result=0;
//加载驱动
static{
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/*request.getRequestDispatcher("https://www.baidu.com").forward(request, response);*/
response.sendRedirect("/webProject1/Pages/Welcome.jsp"); } /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//设置请求字符编码
request.setCharacterEncoding("utf-8");
//设置响应字符编码
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//获取用户名
String userName=request.getParameter("userName");
//密码
String password=request.getParameter("password");
try {
//连接数据库
conn = DriverManager.getConnection(URL,user,key);
//创建SQL语句对象
Statement stmt=conn.createStatement();
String sql="insert into denglu(userName,mima) values('"+userName+"','"+password+"')";
result= stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}
if(result==1)
{
//response.sendRedirect(request.getContextPath()+"/jsp-login/welcome.jsp");
//request.getRequestDispatcher("/Pages/DengLu.jsp?userN="+userName).forward(request, response);
request.getRequestDispatcher("/Pages/DengLu.jsp").forward(request, response);
}
else
{
request.setAttribute("error", "注册失败!");
request.getRequestDispatcher("/Pages/ZhuCe.jsp").forward(request, response);
}
} }

3.登录端

 <%@ 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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="Servlet" method="get">
用户名:<input type="text" name="userName1"/><br/>
密码:<input type="password" name="password1"/><br/>
<button type="submit">登录</button>
<button type="reset">重置</button>
</form>
</body>
</html>

4.欢迎页面

 <%@ 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=UTF-8">
<title>Insert title here</title>
</head>
<body>
welcome!
</body>
</html>

servlet之注册登录(简写)的更多相关文章

  1. JavaWeb_利用Servlet处理注册登录请求

    利用Servlet处理注册登录请求 程序结构 <%@page import="com.Gary.model.User"%> <%@ page language=& ...

  2. JavaWeb笔记——注册登录系统项目思路

    功能:   > 注册   > 登录 --------------------------------- JSP:   * login.jsp  --> 登录表单   * regist ...

  3. 注册登录系统项目思路 -- javaweb

    功能:   > 注册   > 登录   ---------------------------------   JSP:   * login.jsp  --> 登录表单   * re ...

  4. servlet数据库验证登录

    servlet数据库验证登录 一.将数据库连接和验证封装为一个单独的类 import java.sql.*; public class SQLtest { // JDBC 驱动名及数据库 URL st ...

  5. Android:注册登录

    注册登录的实现 先在layout里新建一个xml文件: //login.xml <?xml version="1.0" encoding="utf-8"? ...

  6. Servlet实现用户登录

    1.登录过程分析: 通过表单收集用户的数据,Servlet通过request对象获得用户提交的数据,服务器还需要从数据库中通过sql语句查询有没有表单提交的数据中的用户.有则登录成功,否则,登录失败. ...

  7. JSP注册登录页教程

    转载请标明原文地址:http://www.cnblogs.com/zhangyukof/p/6785258.html  一.准备工作 已搭建好的SSH框架工程一个,如果没有,请参考我的上一篇文章< ...

  8. 基于javaweb人脸识别注册登录系统

    ---恢复内容开始--- 现在是2019年,人脸识别技术已经相当成熟了,百度自2017年发布人脸识别技术,已经被广泛应用,不管从现在的iphoneX掀起的面部解锁到手机应用端的各种人脸认证,这一技术已 ...

  9. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑

    (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...

随机推荐

  1. 安装JDK,配置环境变量有感

    前天无事,心血来潮给公司新配的笔记本(win10系统64位)装开发工具,然后不可避免的就装了JDK,顺理成章的需要配置环境变量,结果就出问题了. 配置完成,测试时,在dos命令窗口输入java命令执行 ...

  2. WPF MVVM 架构 Step By Step(3)(把后台代码移到一个类中)

    我觉得大部分开发者应该已经知道怎么去解决这个问题.一般都是把后台代码(GLUE code)移动到一个类库.这个类库用来代表UI的属性和行为.任何代码当被移到一个类库中时都可以被编译成一个DLL,然后可 ...

  3. nmon用法

    一.简介 nmon是一个简单的性能监测工具,可以监测CPU.内存.网络等的使用情况.它是一个系统监视.调优.性能测试工具,它能一次性提供大量性能相关的信息. 二.安装与执行 下载地址:http://n ...

  4. 编译安装nginx却requires the PCRE library

    编译安装nginx需要pcre包,未安装会有如下提示: ./configure: error: the HTTP rewrite module requires the PCRE library. Y ...

  5. cesium自定义气泡窗口infoWindow后续优化篇

    http://www.cnblogs.com/giserhome/p/6248858.html该篇文章实现的自定义气泡窗口是基于修改cesium源代码基础上,这种做法只是援兵之计,凑合应付的,投机取巧 ...

  6. excel转html 实现在线预览

    首先说一下,本人发布的代码都是经过本人亲测,并且用在实际项目中.如果觉得可以,希望大家点个赞,谢谢大家. 有什么问题,大家评论出来,一起交流.好了,不废话了,下面来说一说这个东西怎么做. 网上也有许多 ...

  7. 更改zendstudio花括号匹配显示的方法

  8. [leetcode-535-Encode and Decode TinyURL]

    TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/desi ...

  9. jzoj3760. 【BJOI2014】Euler

    题目大意: 欧拉函数  φ(n)  定义为不超过正整数 n 并且与 n 互素的整数的数目. 可以证明 φ(n) =  n ∗ ∏ (1 − 1 / pi). 其中 pi(1 <= i <= ...

  10. Loadrunner--自动关联和手动关联

    2017-06-09 15:32:45个人也属于刚刚开始学习,有什么不对的地方敬请指导:qq:389791447 一开始的时候,准备去学习怎么去关联.一时也毛不着头脑,就在网上找了一些视频看,有的人说 ...