Insert_User.java
上传用户:huaxinghn
上传日期:2022-04-20
资源大小:673k
文件大小:1k
- package lilin.servlet;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.SQLException;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import lilin.dao.DB;
- public class Insert_User extends HttpServlet {
-
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- this.doPost(request, response);
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- request.setCharacterEncoding("utf-8");
- response.setContentType("text/html;charset=utf-8");
- PrintWriter out = response.getWriter();
-
- String name = request.getParameter("name");
- String password = request.getParameter("password");
-
- DB db_ref = null;
- try {
- db_ref = new DB();
- boolean is_true = db_ref.insert_User(name, password);
-
- if(is_true){
- int id = db_ref.select_UserByNamePwd(name, password);
- out.println(1+id);
- }else{
- out.println(0);
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- db_ref.closeAll();
- }
-
- out.flush();
- out.close();
- }
- }