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>