JavaEE_Test2_Servlet
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"> </p>
</body>
</html>
JavaEE_Test2_Servlet的更多相关文章
随机推荐
- 第六章 组件 60 组件切换-应用切换动画和mode方式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- myBatis整合Spring理论
整合目标 更少的编码 更少的配置 足够的灵活性 1.更少的编码 只写接口,不写实现(myBatis帮我们实现接口) 2-1.更少的配置-别名 在java的规范当中,表示一个类型是通过包名+类名,但是整 ...
- 个人的web商城网站
项目介绍 1.作为前端的菜鸟,每每看到Github上有很多大神分享着自己的项目时,内心都是蠢蠢欲动,这次终于下定决心要给自己一段时间来完成属于自己的一份作品.2.于是在查找了大量资料,思考着技术选型, ...
- Linux的SSH免密登录(一)
1.从cp/scp命令出发 scp(secure copy)是linux系统下基于ssh登录进行安全的远程文件拷贝的命令. 1. 传递文件到远程 scp local_file remote_usern ...
- Mac终端神器zsh
Mac终端神器zsh 先上一张图 1.背景介绍 在unix 内核的操作系统中,当然现在衍生出好多分支,linux ,OS X 都算. shell 就算和上面这些系统内核指令打交道的一座桥梁,我们通过键 ...
- c++几个通用工具
Pairs(对组) 1.class pair可以将两个值视为一个单元,C++标准程序库内多处使用这个class.尤其容器类别map和multimap,就是使用pairs来管理其键值/实值(key/va ...
- 51 Nod 1035 最长的循环节 (此题还不是很懂,日后再看)
转自: https://blog.csdn.net/define_danmu_primer/article/details/52456763 51nod 1035 最长的循环节(无限小数的循环节) 2 ...
- MySQL_8.0与5.7区别之账户与安全
一.创建用户和用户授权 MySQL5.7创建用户和用户授权命令可以同时执行 grant all privileges on *.* to 'Gary'@'%' identified by 'Gary@ ...
- Rust格式化输出
打印操作由 https://doc.rust-lang.org/std/fmt/ 里面所定义的一系列宏来处理,包括: format!:将格式化文本写到字符串(String).(译注:字符串是返 回值不 ...
- mumu 连接安卓studio
近期开发一个项目,折腾了好久,编写完程序后,真机上运行没有异常,而在MuMu模拟器上运行,程序总是中断(MuMu模拟器连接不上,只能打包好apk再放到MuMu上测试,有点蠢萌...),没办法调试,就获 ...