学习练习 使用Servlet实现用户注册功能
2016-07-01 15:28
393 查看
package com.hanqi.www; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Test111 extends HttpServlet { private static final long serialVersionUID = 1L; public Test111() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); String us = request.getParameter("username"); String pw = request.getParameter("password"); String pw1 = request.getParameter("password1"); //判断是否正确接收 if(us != null && pw != null && pw1 != null) { if(!us.equals("")) { if(pw.equals(pw1)) { //记录用户信息 //跳转到系统主页面 response.sendRedirect("Main.jsp"); } else { //否则就提示登录错误 response.getWriter().write("请输入相同的密码"); } } else { response.getWriter().write("帐号或密码不能为空字符串"); } } else { response.getWriter().write("请正确输入您的信息"); } response.getWriter().append("Served at: ").append(request.getContextPath()); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
<%@ 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> 注册成功 </body> </html>
<%@ 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> 注册页面 <br> <% //销毁session session.invalidate(); %> <form action="testpw" method = "get"> 账户:<input type="text"name = "username"><br> 密码:<input type="password"name = "password"><br> 确认密码:<input type="password"name = "password1"><br> <input type="submit" value="注册"> </form> </body> </html>
相关文章推荐
- [改善Java代码]用枚举实现工厂方法模式更简洁
- 使用SpringMVC参数传递时,解决get请求时中文乱码的问题
- nginx配置多个站点
- Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 并查集求奇偶元环
- Spring 基于xml配置方式的事务
- js Array数组的使用
- 发布Android Library项目到JCenter的便捷方法
- 对比PHP对MySQL的缓冲查询和无缓冲查询
- php实现多文件上传
- sql server-Convert DateTime 格式的转换
- Java中的数组和方法
- 腾讯信鸽推送基本流程和数据的处理流程
- 数据结构之【排序】--复习
- 互联网2.0大事记
- iOS图片转base64字符串和base64字符串转为图片
- Extjs--checkbox,选中与不选中
- AngularJS内建服务$location及其功能详解
- android 极细线
- 关于java UTF-8中文与Unicode编码之间转换,以及将浏览器地址栏编码过的中文转换UTF-8形式
- 安卓4.0开发平台搭建 图文详细 教程