通过servlet连接数据库和HTML,完成登陆注册
来源:互联网 发布:游戏秘籍输入器源码 编辑:程序博客网 时间:2024/06/07 17:17
提交onsubmit()方法,重置onreset()方法:
<form onsubmit="test()" onreset="dos()">邮箱:<input type="text" id="qq"/>密码:<input type="password" id="ee"/><input type="submit" value="提交" /><input type="reset" value="重置" /></form>
实例:通过其判断邮箱以及密码的值为不为空
js代码块:
function test(){var flag=true;var ww=document.getElementById("qq");var rr=document.getElementById("ee");if((ww.value=="")&&(rr.value=="")){alert("不能都为空")flag=false;return flag;}else if(ww.value==""){alert("邮箱不能为空");flag=false;return flag;}else if(rr.value==""){alert("密码不能为空")flag=false;return flag;}else{alert("提交成功")}return flag;}function dos(){var x=confirm("确定重置?");}
通过Servlet连接HTNL以及数据库,完成登陆注册界面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>jiemian.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--><style type="text/css"></style><script type="text/javascript">function denglu(){var flag=true;var ww=document.getElementById("qq");var rr=document.getElementById("ee");if((ww.value=="")&&(rr.value=="")){alert("不能都为空")flag=false;//return flag;}else if(ww.value==""){alert("账号不能为空");flag=false;//return flag;}else if(rr.value==""){alert("密码不能为空")flag=false;//return flag;}else{alert("提交成功")}return flag;}</script></head> <body><div id="01" align="center" style="background-color:#9CF; height:400px;width:350px; margin-left:800px;"><p><h1>登录界面</h1></p> <form action="MyServlet" onsubmit="denglu()"> 账 号:<input id="qq" type="text" name="username" > <br /> 密 码:<input id="ee" type="password" name="password"> <br /> <input type="submit" value="登录" /> <input type="button" value="注册" /> </form> </div></body></html>
servlet:
package Servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.HashMap;import java.util.Map;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import po.User;import dao.UserDao;public class MyServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//设置编码response.setCharacterEncoding("UTF-8");request.setCharacterEncoding("UTF-8");response.setContentType("text/html"); String username=request.getParameter("username");String password=request.getParameter("password");UserDao userDao=UserDao.getInstance();Map<String,String> map=new HashMap<String,String>();map.put("username", username);map.put("password", password);User user=userDao.getUserByMap(map);if(user!=null){request.getRequestDispatcher("/success.jsp").forward(request, response);return;}else{request.getRequestDispatcher("/zhuce.jsp").forward(request, response);return;}}}
注册界面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'zhuce.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript">function check(){var hh=true;var x=document.getElementById("first").value;var y=document.getElementById("second").value;if(x!=y){alert("对不起密码不一致,请重新输入")hh=false;}return hh;}</script> </head> <body><div align="center" style="background-color:#9CF; width:350px; height:400px; margin-left:800px;"><p><h1>注册界面</h1></p> <form action="MyServlet11" onsubmit="check()"> 请输入账号:<input type="text" name="username"/> <br /> <br /> <br /> <br /> 请输入密码:<input id="first" type="password" name="password"/> <br /> <br /> <br /> <br /> 再输入密码:<input id="second" type="password" /> <br /> <br /> <br /> <br /> 请输入性别:<input type="text" name="sex"/> <br /> <br /> <input type="submit" style="width:200px;" value="提交" /> </form></div> </body></html>
阅读全文
0 0
- 通过servlet连接数据库和HTML,完成登陆注册
- Android通过Servlet连接MySQL 实现登陆/注册(数据库+服务器+客户端)
- 复习连接数据库--制作SQLHelper类完成登陆注册
- JDBC连接数据库,完成注册和登录
- 一个完整的Nodejs项目 完成连接数据库(MySQL),登陆、注册功能 session的使用 和发送邮件
- Android通过Http连接MySQL 实现登陆/注册(数据库+服务器+客户端)
- Android通过Http连接MySQL 实现登陆/注册(数据库+服务器+客户端)
- Android通过Http连接MySQL 实现登陆/注册(数据库+服务器+客户端),android+mysql
- Android通过Http连接MySQL 实现登陆/注册(数据库+服务器+客户端)
- Android通过Http连接MySQL 实现登陆/注册(数据库+服务器+客户端),androidmysql
- Servlet+JavaBean实现注册和登陆
- servlet通过JDBC连接数据库
- html登陆按钮和注册按钮
- JSP_实现Servlet登陆,注册,链接Mysql数据库。
- 通过jsp和servlet实现后台界面完成对数据库的增删改查
- Android通过Http连接MySQL 实现登陆/注册(数据库+service+客户端)【大部分转自帮客之家】
- 利用SQLite数据库实现登陆和注册
- js操作数据库实现注册和登陆
- 理解事务的4种隔离级别
- 堆排序
- dts list python tool
- Facebook加入直播功能,带你窥探虚拟现实世界
- 如何使用dreamweave cc给图片加热点链接?
- 通过servlet连接数据库和HTML,完成登陆注册
- Leetcode-Valid Sudoku
- 第六章项目时间管理
- 每日vim系列0713
- 前端学习(二)mac安装nvm
- 多线程之NSOperation
- linux 下安装MySQL出现问题 Access denied for user ''@'localhost' to database 'mysql'
- 使用sklearn做各种回归
- SDK测试、移动应用测试解决方案—昆山中创软件工程有限公司