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. vue的store状态管理模式

    var store = { debug: true, state: { message: 'Hello!' }, setMessageAction (newValue) { //所有 store 中 ...

  2. electron-vue 引入OpenLayer 报错 Unexpected token export

    electron-vue 引入OpenLayer 报错 Unexpected token export 解决办法: 在 .electron-vue/webpack.renderer.config.js ...

  3. jquery button选择器 语法

    jquery button选择器 语法 作用::button 选择器选取类型为 button 的 <button> 元素和 <input> 元素.大理石平台价格表 语法:$(& ...

  4. Linux 打印可变参数日志

    实现了传输进去的字符串所在的文档,函数和行数显示功能. 实现了将传入的可变参数打印到日志功能. #include<stdio.h> #include<stdarg.h> #in ...

  5. 7.2 Mybatis

    7.2 Mybatis 平时我们都用JDBC访问数据库,除了需要自己写SQL之外,还必须操作Connection, Statement, ResultSet 这些其实只是手段的辅助类. 不仅如此,访问 ...

  6. 同样的WiFi,手机能连上网,电脑不能。错误代码DNS_PROBE_POSSIBLE

    今天电脑不知打为撒,出了这样个毛病,原因不明.先试着用电脑管家修复,无效.找了网上的很多办法,排除了dns.ip之类的问题.最后在贴吧里看到大神的解决办法,实测简单有效.链接http://tieba. ...

  7. springboot的@EnableAutoConfiguration起作用的原理

    通常我们启动一个springboot项目会在启动方法中增加@SpringBootApplicatoin注解,该注解中包含了@EnableAutoConfiguration @Target(Elemen ...

  8. (十七)C语言之变量

  9. php phpexcel 创建excel

    public function createExcel($result=[],$fileName=''){ \think\Loader::import('extend.excel.PHPExcel', ...

  10. 【软件工程】Alpha冲刺(1/6)

    链接部分 队名:女生都队 组长博客: 博客链接 作业博客:博客链接 小组内容 恩泽(组长) 过去两天完成了哪些任务 描述 了解了反馈机制的实现原理 确定好算法的框架 对接口的规范化进行学习 展示Git ...