regist.java

来自「基于Spring2.5的精品课程网站」· Java 代码 · 共 60 行

JAVA
60
字号
package org.adam.servlet;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.adam.bean.StudentBean;
import org.adam.bean.TeacherBean;
import org.adam.service.StudentService;
import org.adam.service.TeacherService;
import org.adam.tools.Factory;
@SuppressWarnings("serial")
public class Regist extends HttpServlet {

	/**
	 * 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 {

		response.setContentType("text/html;charset=gbk");
		request.setCharacterEncoding("GBK");
		response.setCharacterEncoding("GBK");
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		String email=request.getParameter("email");
		String status=request.getParameter("status");
		if("teacher".equals(status)){
			TeacherBean teacher=new TeacherBean();
			teacher.setTeachername(username);
			teacher.setTeacherpass(password);
			teacher.setTeacheremail(email);
			teacher.setState(0);
			TeacherService teacherService=(TeacherService)Factory.getBeanName("teacherService");
			teacherService.insert(teacher);
			response.sendRedirect("registsuccess.html");
		}else if("student".equals(status)){
			StudentBean student=new StudentBean();
			student.setStudentname(username);
			student.setStudentpass(password);
			student.setStudentemail(email);
			StudentService studentService=(StudentService)Factory.getBeanName("studentService");
			studentService.regist(student);
			response.sendRedirect("registsuccess.html");
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?