package servlet;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
public class Register extends javax.servlet.http.HttpServlet {
private void doProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
String studentName = request.getParameter("studentName");
String pairname = request.getParameter("pairname");
String parentname = request.getParameter("parentname");
String p1 = request.getParameter("password");
String p2 = request.getParameter("password2");
String type = request.getParameter("catagloryID");
System.out.println("studentName" + studentName);
System.out.println("pairname" + request.getParameter("pairname"));
System.out.println("parentname" + request.getParameter("parentname"));
System.out.println("password" + p1);
System.out.println("password2" + p2);
HttpSession session = request.getSession();
session.setAttribute("studentName",studentName);
session.setAttribute("pairname",pairname);
session.setAttribute("parentname",parentname);
if(type == null)
{
session.setAttribute("wrongMsgType","必须选择其中之一");
}
if(type == "1")
{
System.out.println("catagloryID" + "初中英语");
}
else if(type == "2")
{
System.out.println("catagloryID" + "TOEFL");
}
else if(type == "5")
{
System.out.println("catagloryID" + "高中英语");
}
else if(type == "6")
{
System.out.println("catagloryID" + "GRE");
}
else if(type == "7")
{
System.out.println("catagloryID" + "SAT");
}
request.setAttribute("studentName",studentName);
request.setAttribute("pairname",pairname);
request.setAttribute("parentname",parentname);
if(!p1.equals(p2))
{
session.setAttribute("wrongMsgPw","两次密码不同");
}
request.getRequestDispatcher("register.jsp").forward(request,response);
}
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
doProcess(request,response);
}
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
doProcess(request,response);
}
}
 <%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Register User</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="English word">
</head>
<style>
h7 {
color:red;
}
</style>
<body bgcolor="#DFFFBF">
<h1>注册信息:</h1>
<hr/> <form id="registerForm" name="registerForm" method="post" action="Register" >
<table>
<tr> </tr>
<tr align="left">
<td align="right" width="100px" class="inputLabel">学生姓名: </td>
<td align="left" width="100px">
<%-- 方法一 使用if-else实现输出和不输出--%>
<%-- <%--%>
<%-- if(request.getAttribute("studentName") != null){--%>
<%-- %>--%>
<%-- <input class="inputFrame" type="text" id="studentName" name="studentName" value="<%=request.getAttribute("studentName")%>"></td>--%>
<%-- <td align="right" width="100px" class="inputLabel">帮背者姓名:</td>--%>
<%-- <td align="left" width="100px"><input class="inputFrame" type="text" id="pairname" name="pairname" value="<%=request.getAttribute("pairname")%>"></td>--%>
<%-- <td align="right" width="100px" class="inputLabel">父母姓名 :</td>--%>
<%-- <td align="left" width="100px"><input class="inputFrame" type="text" id="parentname" name="parentname" value="<%=request.getAttribute("parentname")%>"></td>--%> <%-- <%--%>
<%-- }else{--%>
<%-- %>--%>
<%-- <input class="inputFrame" type="text" id="studentName" name="studentName" value=""></td>--%>
<%-- <td align="right" width="100px" class="inputLabel">帮背者姓名:</td>--%>
<%-- <td align="left" width="100px"><input class="inputFrame" type="text" id="pairname" name="pairname" value=""></td>--%>
<%-- <td align="right" width="100px" class="inputLabel">父母姓名 :</td>--%>
<%-- <td align="left" width="100px"><input class="inputFrame" type="text" id="parentname" name="parentname" value=""></td>--%> <%-- <%--%>
<%-- }--%>
<%-- %>--%>
<%-- 方法二,使用el,自动回填--%>
<input class="inputFrame" type="text" id="studentName" name="studentName" value="${studentName}"></td>
<td align="right" width="100px" class="inputLabel">帮背者姓名:</td>
<td align="left" width="100px"><input class="inputFrame" type="text" id="pairname" name="pairname" value="${pairname}"></td>
<td align="right" width="100px" class="inputLabel">父母姓名 :</td>
<td align="left" width="100px"><input class="inputFrame" type="text" id="parentname" name="parentname" value="${parentname}"></td> </tr>
<tr align="left">
<td align="right" width="100px" class="inputLabel">密码:</td>
<td align="left" width="100px"><input class="inputFrame" type="password" id="password" name="password" > </td>
<td align="right" width="100px" class="input.label">确认密码:</td>
<td><input class="inputFrame" type="password" id="password2" name="password2">
<td>
<%
String pwMsg = (String)session.getAttribute("wrongMsgPw");
if(pwMsg != null)
out.println("<h7>" + pwMsg + "</h7>");
session.setAttribute("wrongMsgPw",null);
%>
</td>
<td></td>
</tr>
<tr>
<td colspan="4" class="alert">
<div id="checkUser"> </div> </td>
</tr>
<tr height="5px">
<td colspan="6">请选择需要背的单词(后期可更改):
<%
String typeMsg = (String)session.getAttribute("wrongMsgType");
if(typeMsg != null)
out.println("<h7>" + typeMsg + "</h7>");
session.setAttribute("wrongMsgType",null);
%>
</td>
</tr> <tr><td align="center"><input type="radio" id="catagloryID1" name="catagloryID" value="6"></td>
<td align="center" colspan="3">GRE</td>
</tr> <tr><td align="center"><input type="radio" id="catagloryID1" name="catagloryID" value="2"></td>
<td align="center" colspan="3">TOEFL</td>
</tr> <tr><td align="center"><input type="radio" id="catagloryID1" name="catagloryID" value="7"></td>
<td align="center" colspan="3">SAT</td>
</tr> <tr><td align="center"><input type="radio" id="catagloryID1" name="catagloryID" value="5"></td>
<td align="center" colspan="3">高中英语 </td>
</tr> <tr><td align="center"><input type="radio" id="catagloryID1" name="catagloryID" value="1"></td>
<td align="center" colspan="3">初中英语 </td>
</tr> <tr height="5px"></tr>
<tr><td colspan="4" align="center"><input class="button gray" type="submit" value="Submit" ></td> </tr>
</table> </form>
<p class="tips">&nbsp;</p>
</body>
</html>

JavaEE_Test2_Servlet的更多相关文章

随机推荐

  1. 计划任务 at,cron

    示例:每3小时echo和wall命令

  2. Vue习题作业练习

    作业一: 用table表格标签渲染以上数据,表格第一列是学生总分排名,最后一列是学生总分 <!DOCTYPE html> <html lang="en"> ...

  3. PHP类知识----值传递和引用传递

    JS中数组是引用传递 PHP除了资源和对象等数据类型,其数据类型是值传递(即使数组也如此) 栈内存(快速内存)中存放标量数据类型,复合数据类型的变量名和数据地址 在内存中,我们可以认为内存中有很多格子 ...

  4. nginx 访问控制模块

    截图,代码截屏均引用自慕课网nginx相关教学视频 基于用户的访问控制模块 http_access_module 基于用户登录信任的模块 http_access_module 参数示意:address ...

  5. BZOJ 3594: [Scoi2014]方伯伯的玉米田 (二维树状数组优化DP)

    分析 首先每次增加的区间一定是[i,n][i,n][i,n]的形式.因为如果选择[i,j](j<n)[i,j](j<n)[i,j](j<n)肯定不如把后面的全部一起加111更优. 那 ...

  6. 03 深入远程执行:target目标、模块modules、返回returns

    0.学习目的 http://docs.saltstack.cn/topics/execution/index.html  官方文档 0.1 命令解释 [root@host---- ~]# salt ' ...

  7. CodeForces 830B - Cards Sorting

    将每个数字的位置存进该数字的vector中 原数组排个序从小到大处理,每次在vector里二分找到距离当前位置“最远”的位置(相差最大),更新答案 树状数组维护每个数字现在的位置和原位置之差 #inc ...

  8. nodejs(上)(获取请求参数)

    Node.js是一个让JavaScript运行在服务器端的开发平台    参考文章 nodejs特点: 单线程 异步非阻塞i/o(异步相对节省资源,把那个等待的时间利用上了) 事件驱动 稳定性差(因为 ...

  9. Navicat导出表结构

    SQL Server导出表结构 Oracle导出表结构

  10. 51 Nod 1636 教育改革(dp)

    1636 教育改革  题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 最近A学校正在实施教育改革. 一个学年由n天 ...