发表于: 2017-11-02 23:31:39

1 758


今天完成的事情:

重新设计注册接口和登录接口..遇到的问题还挺有意思.

    @RequestMapping(value = "/enrolmentUser", method = RequestMethod.POST)
public String addUser(HttpServletRequest request, HttpServletResponse response, Model model, Student student) {
try {
//            设置编码
           request.setCharacterEncoding("utf-8");
           response.setCharacterEncoding("utf-8");
//            获取从页面提交过来的数据
           student.setUserName(request.getParameter("userName"));
           student.setUserPassword(request.getParameter("userPassword"));
//            数据类型转换
           student.setQq(Integer.parseInt(request.getParameter("qq")));
           loggerController.info(student);
           int i = studentService.addStudentUser(student);
           loggerController.info("被添加的学员信息" + i);
           if (i == 1) {
return "/common/success";
           }
} catch (Exception e) {
e.printStackTrace();
           loggerController.error(e.getMessage());
       }
return "common/faile";
   }
     * 用户登录
    */
   @RequestMapping(value = "/login/v", method = RequestMethod.POST)
public String selectUserName(HttpServletRequest request, HttpServletResponse response, Model model) {
try {
loggerController.info(request.getParameter("userName"));
           String userKey = studentService.selectUser(request.getParameter("userName"));
           String userPassword = request.getParameter("userPassword");
           loggerController.info("用户密码" + userPassword);
           if (userKey.equals(userPassword)) {
response.setHeader("refresh", "0;url=/a/home");
               return "";
           }
} catch (Exception e) {
e.printStackTrace();
           loggerController.error(e.getMessage()); }
return "/regist/regist";
   }

}

对登录账户和用户登录的当前时间进行des加密.

@RequestMapping(value = "/login/v", method = RequestMethod.POST)
public String selectUserName(HttpServletRequest request, HttpServletResponse response, Model model,String userName) {
try {
loggerController.info(request.getParameter("userName"));
       String userKey = studentService.selectUser(request.getParameter("userName"));
       String userPassword = request.getParameter("userPassword");
       loggerController.info("用户密码" + userPassword);
       if (userKey.equals(userPassword)) {
long time =System.currentTimeMillis();
              Cookie cookie = new Cookie("token"desUtil.encrypt(userName),(desUtil.encrypt(String.valueOf(time))));
              cookie.setMaxAge(60*60*24*7);
              cookie.setPath("/");
           response.addCookie(cookie);
           response.setHeader("refresh", "0;url=/a/home");
           return "";
       }
} catch (Exception e) {
e.printStackTrace();
       loggerController.error(e.getMessage()); }
return "/regist/regist";
}

明天计划的事情:

增加删除Cookie,

对代码进行完善.

完成深度思考

提交任务5


遇到的困难:

没有截图...在进入登录页面之后输入正确账户密码情况下无法进入首页,没有输入账户密码情况下,用户账户也了值.在师兄的帮助下,发现是跳转页面的问题,如果是从别的页面转入的情况下,是会继续上一个请求头里面的内容继续访问.所以在没有输入任何值得情况下登录页面也有账户的值..解决问题添加一个登录页面即可.


收获:

setHeader()方法

用setHeader()方法设置响应头,为刷新“refresh”,然后设置几秒后刷新的时间和url地址.

sendRedirect()方法请求重定向response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8");然后就会重新定向到相应的servlet.

获取当前时间戳的三种方法

方法 一System.currentTimeMillis();

方法 二Calendar.getInstance().getTimeInMillis();

方法 三new Date().getTime();.

强制转换类型

String.valueOf


任务开始时间2017-10-23

任务结束时间2017-11-05

无延期风险.

禅道http://task.ptteng.com/zentao/task-view-12736.html





返回列表 返回列表
评论

    分享到