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. Web界面开发必看!Kendo UI for jQuery编辑功能指南第一弹

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  2. 解决power designer 不能自动生成注释 commont 的解决办法只需要3步:

    解决power designer 不能自动生成注释的解决办法只需要3步: 一.快捷键 Ctrl+Shift+X 打开脚本编辑器:(快捷键不能执行的话可以从这个路径执行:Tools --> Exc ...

  3. github高速下载的方法

    windows修改host文件: C:\Windows\System32\drivers\etc\hostslinux 修改host文件: /etc/hosts 在文件后面加上这两行 151.101. ...

  4. 归并排序java代码

    //归并排序 通过测试 public class MergeSortTest{ public static void mergeSort(int[] data,int low,int high){ i ...

  5. 使用SpringSession和Redis解决分布式Session共享问题

    SpringSession优势 遵循servlet规范,同样方式获取session,对应用代码无侵入且对于developers透明化 关键点在于做到透明和兼容 接口适配:仍然使用HttpServlet ...

  6. c++实例之通讯录管理系统之清空联系人功能(七)

    #include<iostream> using namespace std; constexpr auto MAX = ; //联系人结构体 struct Person { string ...

  7. Linux和其他机器共享文件

    在实际当中,Linux服务器在公网上,我们的windows电脑在局域网中,因此这个共享并不实际. 安装vsftpd 注:安装之后需要验证ftp是否工作,这时应该在本机验证,而不应该在windows电脑 ...

  8. DOM访问关系(父节点 子节点)

    把下面的知识点掌握了,可以做一下下面的案例,都是工作中常用的,很有用 知识点   1.带Eleent和不带区别     a)带Element的获取的是元素节点     b)不带Element的获取文本 ...

  9. JVM-GC算法(二)-复制算法&&标记整理算法

    这次我和各位分享GC最后两种算法,复制算法以及标记/整理算法.上一篇在讲解标记/清除算法时已经提到过,这两种算法都是在此基础上演化而来的,究竟这两种算法优化了之前标记/清除算法的哪些问题呢? 复制算法 ...

  10. LeetCode 42. 接雨水(Trapping Rain Water)

    题目描述 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水. 上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况 ...