public class Regist1Servlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//获得性别
String gender = ("gender");
//获得职位
String job = ("job");
//根据request获得session, 如果session已存在就直接使用当前会话的session,如果不存在就创建新的session对象
HttpSession session = ();
//从session中获得用户和密码,返回的是Object需要强转为String类型
String username = (String)("username");
String password = (String) ("password");
//获得session的id,session利用id和浏览器的cookie进行绑定用来区分会话
String sessionID = ();
(sessionID);
switch(gender){
case "1" :
gender="男";
break;
case "2" :
gender="女";
break;
}
switch(job){
case "1" :
job="讲师";
break;
case "2" :
job="构架师";
break;
}
//设置response的类型和编码
("UTF-8");
("text/html;charset=UTF-8");
//打印到页面上
().println("<h1>注册成功</h1>");
().println("<hr>");
().println("用户名:"+username+"<br>");
().println("密码:"+password+"<br>");
().println("性别:"+gender+"<br>");
().println("职位:"+job+"<br>");
}
}