首页 > 其他分享 >今日总结

今日总结

时间:2023-03-05 17:33:26浏览次数:44  
标签:总结 userName String request HttpServlet import 今日 response

package com.maike.dao;
 
 import com.maike.model.User;

 public interface UserDao {
     
     int insert(String userName,String userPwd);
     User selectByName(String userName);
 
 }
UserDao
package com.maike.controller;
 
 import java.io.IOException;
 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.maike.service.UserService;
 import com.maike.service.UserServiceImpl;
 
 /**
  * Servlet implementation class LoginServlet
  */
 @WebServlet("/LoginServlet")
 public class LoginServlet extends HttpServlet {
     UserService userService = new UserServiceImpl();
     private static final long serialVersionUID = 1L;
        
     /**
      * @see HttpServlet#HttpServlet()
      */
     public LoginServlet() {
         super();
         // TODO Auto-generated constructor stub
     }
 
     /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         // TODO Auto-generated method stub
         response.getWriter().append("Served at: ").append(request.getContextPath());
     }
 
     /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         // TODO Auto-generated method stub
         request.setCharacterEncoding("utf-8");
         String userName = request.getParameter("userName");
         String uesrPwd = request.getParameter("userPwd");
         
         int k = userService.judgeLogin(userName,uesrPwd);
         if(k > 0) {
             request.getRequestDispatcher("success.jsp").forward(request, response);
         }else {
             request.getRequestDispatcher("login.jsp").forward(request, response);
         }
     }
 
 }
LoginServlet
package com.maike.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.maike.service.UserService;
import com.maike.service.UserServiceImpl;

/**
 * Servlet implementation class RegisterServlet
 */
 @WebServlet("/RegisterServlet")
 public class RegisterServlet extends HttpServlet {     UserService userService = new UserServiceImpl();
     private static final long serialVersionUID = 1L;
        
     /**
      * @see HttpServlet#HttpServlet()
      */
     public RegisterServlet() {
         super();
        // TODO Auto-generated constructor stub
     }
 
     /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub
         response.getWriter().append("Served at: ").append(request.getContextPath());
     }
 
     /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
         request.setCharacterEncoding("utf-8");
         String userName = request.getParameter("userName");
         String userPwd = request.getParameter("userPwd");
         String userRePwd = request.getParameter("userRePwd");
         
         int k = userService.insertUser(userName,userPwd,userRePwd);
        
        if(k > 0) {
            request.getRequestDispatcher("login.jsp").forward(request, response);
         }else {
            request.getRequestDispatcher("register.jsp").forward(request, response);
         }
     }
 
 }
RegisterServle
package com.maike.dao;
 
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
 import com.maike.model.User;
 import com.maike.util.ConnectionUtil;
 
 public class UserDaoImpl implements UserDao {
     Connection con = null;
     PreparedStatement pt = null;
     ResultSet rs = null;
     String sql;
 
     @Override
     public int insert(String userName, String userPwd) {
         // TODO Auto-generated method stub
         int k = 0;
         sql = "insert into user value(null,?,?)";
         try {
            con = ConnectionUtil.getConnection();
             pt = con.prepareStatement(sql);
             pt.setString(1, userName);
             pt.setString(2, userPwd);
             k = pt.executeUpdate();
         } catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }finally {
             ConnectionUtil.closeRe(con, pt);
         }
         return k;
     }
 
     @Override
     public User selectByName(String userName) {
         // TODO Auto-generated method stub
         sql = "select * from user where user_name = ?";
         User user = new User();
         try {
             con = ConnectionUtil.getConnection();
             pt = con.prepareStatement(sql);
             pt.setString(1, userName);
             rs = pt.executeQuery();
             
             while(rs.next()) {
                 user.setUserId(rs.getInt("user_id"));
                 user.setUserName(rs.getString("user_name"));
                user.setUserPwd(rs.getString("user_pwd"));
             }
         } catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }finally {
             ConnectionUtil.closeRe(con, pt, rs);
         }
         return user;
     }
 
 }
UserDaoImpl

 

标签:总结,userName,String,request,HttpServlet,import,今日,response
From: https://www.cnblogs.com/zhaoyueheng/p/17181014.html

相关文章

  • 每日总结 3.5
    今天学习了页面显示和闹钟的设定。使用listview显示数据。闹钟仍在研究中。publicclassMainActivityextendsAppCompatActivity{@SuppressLint("MissingInfl......
  • 常用数据结构和算法总结
    线性表:单链表双向链表循环链表栈队列递归字符串数组树二叉树哈夫曼树:又称为最优树,是一种带权路径长度最短的树平很二叉树B树......
  • 以下总结了Java一些面试前准备和技术参考题,希望对你有所帮助
    以下真实模拟JAVA面试场景:感谢您参加我们的面试;以下是我们总结一些面试前准备和技术参考题,希望对你有所帮助。首先,你需要先准备下工作相关的自我介绍,包括以下内容:几年......
  • 每日总结2023/3.5
    4.单选按钮RadioGroupRadioGroup提供的只是一个单选按钮的容器,只有在此容器中配置多个按钮组件之后才可以使用,设置单选按钮则需要使用RadioButton类<LinearLayoutxmlns:a......
  • 2023/3/3每日总结
    设置视图的宽高>视图宽度通过属性android:layoutwidth表达,视图高度通过属性android:layoutheioht表达,宽高的取值主要有下列三种:matchparent:表示与上级视图保持一致wr......
  • Qt插件开发总结5--主界面嵌入插件UI
    文章目录​​一、前言​​​​二、效果展示​​​​三、嵌入插件UI​​​​1、插件接口文件添加UI指针​​​​2、插件子项目工程建立UI类​​​​3、插件类中创建UI类、使U......
  • Java实战(第二版)读后总结与感想
    1. 基本信息Java实战(第二版)ModernJavainAction,2ndEdition[英]拉乌尔–加布里埃尔·乌尔玛(Raoul-GabrielUrma),[意]马里奥·富斯科(MarioFusco),[英]艾伦·米克......
  • 3.4每日总结
    今天顺着菜鸟教程学一点,相对布局部分。margin和padding的区别margin代表的是偏移,比如marginleft="5dp"表示组件离容器左边缘偏移5dp;padding代表的则是填充,而填充的......
  • 今日报告-13
    今日打卡所花时间(包括上课):5h代码量(行):300发表博客:4篇(不包括本篇)了解到的知识点:继续Android学习,进一步每日打卡app,完成了每日打卡APP的注册,登录,打卡功能,正在研究Alarm......
  • 每日总结
    今天开发了记事本plus版本,可以实现增删改查,并且联合listview控件去显示,学到到listview需要适配去去解析页面熟悉了页面跳转的时候消息传递的妙处,也了解到许多未曾用到的函......