Web资源共享

1、Request实现请求转发(与下面的Response实现重定向 区分)

请求转发资源共享数据:使用Request对象

void setAttribute(String name,Object o)存储数据到request域中

Object getAttribute(String name) 根据key 获取值

void removeAttribute(Sting name) 根据key,删除该键值对

案例 web-demo01 

2、Response实现重定向

response.sendRedirect("/web-demo01/resp02");

案例 web-demo01 

3、Cookie

 4、Session

\

1 brand-demo的增 删 该都是用的request的

request.getRequestDispatcher("/selectAllServlet").forward(request,response);

2 brand-demo查询的用的是  只是存上了数据

  //        封装到request域中
        request.setAttribute("brand",brand);
//        转发
        request.getRequestDispatcher("update.jsp").forward(request,response);

3 brand-demo的登录页面用的是

登陆成功    Session资源共享

//            session共享资源
            HttpSession session = request.getSession();
            session.setAttribute("user",user);
//          实现重定向
            response.sendRedirect("/brand-demo/selectAllServlet");

 我自己想的

//            request.setAttribute("login_name", user.getUsername());
//            request.getRequestDispatcher("/selectAllServlet").forward(request, response);

登陆失败  用的是

//            存储信息到request域
            request.setAttribute("login_msg", "用户名或密码错误");
//            转发
            request.getRequestDispatcher("/login.jsp").forward(request, response);

我自己想的

//            HttpSession session = request.getSession();
//            session.setAttribute("login_msg","用户名或密码错误");
//            response.sendRedirect("/brand-demo/login.jsp");

4 brand-demo的登录页面验证码用的是Cookie

//用户勾选了记住用户
Cookie c_username = new Cookie("username", username);
Cookie c_password = new Cookie("password", password);
//记住时间
c_username.setMaxAge(60*60*24*7);
c_password.setMaxAge(60*60*24*7);
//发送Cookie
response.addCookie(c_username);
response.addCookie(c_password);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值