servlet之注册登录(简写)
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之注册登录(简写)的更多相关文章
- JavaWeb_利用Servlet处理注册登录请求
利用Servlet处理注册登录请求 程序结构 <%@page import="com.Gary.model.User"%> <%@ page language=& ...
- JavaWeb笔记——注册登录系统项目思路
功能: > 注册 > 登录 --------------------------------- JSP: * login.jsp --> 登录表单 * regist ...
- 注册登录系统项目思路 -- javaweb
功能: > 注册 > 登录 --------------------------------- JSP: * login.jsp --> 登录表单 * re ...
- servlet数据库验证登录
servlet数据库验证登录 一.将数据库连接和验证封装为一个单独的类 import java.sql.*; public class SQLtest { // JDBC 驱动名及数据库 URL st ...
- Android:注册登录
注册登录的实现 先在layout里新建一个xml文件: //login.xml <?xml version="1.0" encoding="utf-8"? ...
- Servlet实现用户登录
1.登录过程分析: 通过表单收集用户的数据,Servlet通过request对象获得用户提交的数据,服务器还需要从数据库中通过sql语句查询有没有表单提交的数据中的用户.有则登录成功,否则,登录失败. ...
- JSP注册登录页教程
转载请标明原文地址:http://www.cnblogs.com/zhangyukof/p/6785258.html 一.准备工作 已搭建好的SSH框架工程一个,如果没有,请参考我的上一篇文章< ...
- 基于javaweb人脸识别注册登录系统
---恢复内容开始--- 现在是2019年,人脸识别技术已经相当成熟了,百度自2017年发布人脸识别技术,已经被广泛应用,不管从现在的iphoneX掀起的面部解锁到手机应用端的各种人脸认证,这一技术已 ...
- SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑
(1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...
随机推荐
- Bash中的字符串变量扩展
1.向尾部方向的最小化删除 (%) $pathname="/usr/bin/local/bin"$echo ${pathname%/bin*}/usr/bin/local 2.向尾 ...
- html <input type="text" />加上readonly后在各种浏览器的差异。
<html> <body> <p>Name:<input type="text" name="email" /> ...
- DDD领域驱动之干活(四)补充篇!
距离上一篇DDD系列完结已经过了很长一段时间,项目也搁置了一段时间,想想还是继续完善下去. DDD领域驱动之干货(三)完结篇! 上一篇说到了如何实现uow配合Repository在autofac和au ...
- 使用juggle简化网络编程
常规的网络编程,在消息处理上大概会采用如下方式 struct msg{ int msg_id; int msg_len; //...msg_info }; 定义如上的消息结构 接收方接收后,按如上的消 ...
- 【Android Developers Training】 39. 获取文件信息
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- 开始JAVA编程的敲门砖——JAVA开发环境搭建
从头开始的java编程--JAVA开发环境搭建 一.什么是java的开发环境? 顾名思义java的开发环境是提供并保证整个java程序开发运行的必要的环境,搭建java开发环境是开始java编程的敲门 ...
- springmvc常用注解标签详解【转】
转载自:http://www.cnblogs.com/leskang/p/5445698.html 1.@Controller 在SpringMVC 中,控制器Controller 负责处理由Disp ...
- 微信小程序知识总结及案例集锦
微信小程序知识总结及案例集锦 微信小程序的发展会和微信公众号一样,在某个时间点爆发 学习路径 微信小程序最好的教程肯定是官方的文档啦,点击这里直达 微信官方文档 认真跟着文档看一遍,相信有vue前端经 ...
- WAMPServer多站点配置方法
WAMPServer多站点配置方法:1.在C:\wamp\www 新建文件夹test01,在里面新建index.php,内容为 "Hello Test01". 2.C:\wamp\ ...
- Maven-FAQ
1.Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.5...: Q: 第一次使用maven+ecli ...