📄 newuser_servlet.java
字号:
package com.wl.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.wl.db.dao.*;
import com.wl.db.vo.*;
public class NewUser_Servlet extends HttpServlet {
/**
* Constructor of the object.
*/
public NewUser_Servlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("-----------------");
response.setContentType("text/html;charset=gb2312");
String username=request.getParameter("username");
System.out.println("aa");
String pwd1=request.getParameter("pwd1");
String pwd2=request.getParameter("pwd2");
String errormes="";
if(!pwd1.equals(pwd2)){
System.out.println("bb");
errormes="密码不一致!";
request.setAttribute("errormes",errormes );
request.getRequestDispatcher("./NewUerror.jsp").forward(request,response);
}
String email=request.getParameter("email");
String realname=request.getParameter("realname");
String sex=request.getParameter("sex");
String phone=request.getParameter("phone");
String question=request.getParameter("question");
String answer=request.getParameter("answer");
String mainface=request.getParameter("mainface");
String introl=request.getParameter("introl");
System.out.println("cc");
String[] temp=request.getParameterValues("like");
String like="";
if(temp!=null){
for(int i=0;i<temp.length;i++){
like+=temp[i];
}
}
System.out.println("dd");
try{
NewUserDAO dao=new NewUserDAO();
NewUser user=dao.sele_User1(username);
if(user!=null){
System.out.println("ee");
errormes="该用户名已用,注册失败!";
request.setAttribute("errormes", errormes);
request.getRequestDispatcher("./NewUerror.jsp").forward(request, response);
}else{
user=new NewUser();
System.out.println("ff");
user.setUerName(username);
System.out.println("gg");
user.setPwd(pwd1);
user.setEmail(email);
user.setRealName(realname);
System.out.println("hh");
user.setSex(sex);
user.setQuestion(question);
user.setAnswer(answer);
user.setMypage(mainface);
user.setPhone(phone);
user.setHobbies(like);
user.setSelfinforo(introl);
dao.add_User(user);
request.setAttribute("user", user);
try{
request.getSession(true).setAttribute("username", username);
request.getRequestDispatcher("./NewUsuccess.jsp").forward(request, response);
}catch(Exception ex){
ex.printStackTrace();
}
}
}catch(Exception ex){
ex.printStackTrace();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -