Insert_User.java
上传用户:huaxinghn
上传日期:2022-04-20
资源大小:673k
文件大小:1k
源码类别:

Ajax

开发平台:

JavaScript

  1. package lilin.servlet;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.sql.SQLException;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import lilin.dao.DB;
  10. public class Insert_User extends HttpServlet {
  11. public void doGet(HttpServletRequest request, HttpServletResponse response)
  12. throws ServletException, IOException {
  13. this.doPost(request, response);
  14. }
  15. public void doPost(HttpServletRequest request, HttpServletResponse response)
  16. throws ServletException, IOException {
  17. request.setCharacterEncoding("utf-8");
  18. response.setContentType("text/html;charset=utf-8");
  19. PrintWriter out = response.getWriter();
  20. String name = request.getParameter("name");
  21. String password = request.getParameter("password");
  22. DB db_ref = null;
  23. try {
  24. db_ref = new DB();
  25. boolean is_true = db_ref.insert_User(name, password);
  26. if(is_true){
  27. int id = db_ref.select_UserByNamePwd(name, password);
  28. out.println(1+id);
  29. }else{
  30. out.println(0);
  31. }
  32. } catch (ClassNotFoundException e) {
  33. // TODO Auto-generated catch block
  34. e.printStackTrace();
  35. } catch (SQLException e) {
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. }finally{
  39. db_ref.closeAll();
  40. }
  41. out.flush();
  42. out.close();
  43. }
  44. }