注册页面

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3>注册页面</h3>
	
	<form action="/day3/reg" method="POST">
		账号: <input type="text" name="username"/><br/>
		密码: <input type="password" name="password"/><br/>
		性别: 
			<input type="radio" name="gender" value="boy" checked/>男
			<input type="radio" name="gender" value="girl">女<br/>
		爱好:
			<input type="checkbox" name="hobby" value="java" checked/>Java
			<input type="checkbox" name="hobby" value="C" />C
			<input type="checkbox" name="hobby" value="Python" />Python<br/>
		城市: <select name="city">
			<option value="bj">北京</option>
			<option value="sh">上海</option>
			<option value="hz">杭州</option>
		</select><br/>
		介绍:<textarea rows="5" cols="15" name="intro"></textarea><br/>
		<input type="submit" value="朕要注册"/>
	</form>
</body>
</html>

  

package per.mjn._05_register;

import java.io.IOException;
import java.util.Arrays;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// 处理注册的请求
@WebServlet("/reg")
public class RegisterServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
//		System.out.println("RegisterServlet.service()");
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		String gender = req.getParameter("gender");
		String city = req.getParameter("city");
		String intro = req.getParameter("intro");
		String[] hobbys = req.getParameterValues("hobby");
		
		System.out.println(username);
		System.out.println(password);
		System.out.println(gender);
		System.out.println(city);
		System.out.println(intro);
		System.out.println(Arrays.toString(hobbys));
	}
}

  

posted @ 2019-09-05 20:58  青衫客36  阅读(181)  评论(0编辑  收藏  举报