<%@ 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="ZhucServlet" method="post">
用户名<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>
package com.hanqi.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class ZhucServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public ZhucServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
String un=request.getParameter("username");
String pw=request.getParameter("password");
String pw1=request.getParameter("password1");
if(un!=null&&pw!=null)
{
if(pw!=""&&un!="")
{
if(pw.equals(pw1))
{
String n=new String(un.getBytes("ISO-8859-1"),"UTF-8");
response.getWriter().write(n+",恭喜注册成功");
}
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);
}
}