jsp 内置对象response,request,session 以及 cookie 对象的综合例子 和 include指令
来源:互联网 发布:技术军官知乎 编辑:程序博客网 时间:2024/05/16 01:04
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body> <% Cookie[] cook=request.getCookies(); if(cook!=null){ for(Cookie item:cook){ if(item.getName().equals("uname")){ //跳转 session.setAttribute("uname",item.getValue() ); response.sendRedirect("/Day_02shili/session/welcon.jsp"); } } } %><form action="/Day_02shili/session/do.jsp" method="post">用户名<input name="uname" /> 密码 <input name="upwd" type="password" /><input type="submit"/></form></body></html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body> <% //设置编码格式 request.setCharacterEncoding("utf-8"); //获取 值 String uname=request.getParameter("uname"); String upwd=request.getParameter("upwd"); //判断 是否 有数据进来 if("1".equals(uname)&&"1".equals(upwd)){ //跳转 //用 session 保存值 session.setAttribute("uname", uname); //使用 cookie Cookie cook=new Cookie("uname",uname); Cookie cookpwd=new Cookie("upwd",upwd); cook.setMaxAge(60); //用 cook 进行 响应 response.addCookie(cook); response.addCookie(cookpwd); request.getRequestDispatcher("/session/welcon.jsp").forward(request,response); }else{ //如果失败 返回 首页 response.sendRedirect("/Day_02shili/session/login.jsp"); } %></body></html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body> 欢迎你<%=session.getAttribute("uname") %> <hr/> <a href="/Day_02shili/session/loginout.jsp">注销</a></body></html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body> <% //清除 指定的 session 值 session.removeAttribute("uname"); //清除后 跳转到 登录页面 response.sendRedirect("/Day_02shili/session/login.jsp"); %></body></html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body> <% //先判断有没有值 Object uname= session.getAttribute("uname"); if(uname==null){ response.sendRedirect("/Day_02shili/session/login.jsp"); } %></body></html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>图书列表 测试 include 方法</title></head><body> <%@include file="yanZhen.jsp" %> <h1>图书列表 必须登录</h1></body></html>
0 0
- jsp 内置对象response,request,session 以及 cookie 对象的综合例子 和 include指令
- jsp 内置对象response,request,session 以及 cookie 对象的综合例子 和 include指令
- jsp的内置对象request和response
- JSP内置对象的使用 request,response,session(一)
- JSP 学习内置对象:request response session。。。。。的常用方法
- JSP内置对象的使用:request,cookie,session
- JSP内置对象之request和response
- JSP内置对象:request和response
- JSP内置对象:request和response
- JSP九大内置对象---Request,Response,Out,Session,Application,Cookie,Config,Page,Exception
- JSP九大内置对象(Request,Response,Out,Session,Application,Cookie,Config,Page,Exception)
- jsp的九大内置对象和四大作用域以及request和session的区别
- JSP中Session内置对象和Cookie的区别
- jsp内置对象out、request、response、session、application五大常用对象以及Page、pageContext、exception、config
- JSP内置对象二(response和session对象)
- jsp的九大内置对象request response session等常用方法介绍
- JSP内置对象(包括request和response)以及解决url传中文参数出现乱码问题
- JSP中request对象、session对象、Cookie对象的使用
- Android -- Wifi连接流程分析
- 聊聊淘宝天猫个性化推荐技术演进史
- Android广播的发送与接收
- JSP数据交互
- 闭包的7种形式
- jsp 内置对象response,request,session 以及 cookie 对象的综合例子 和 include指令
- Office Online Server 文档在线预览编辑【速成篇】
- 浏览器同源策略的行为限制以及规避方法
- 如何写回调函数
- 关于vue.js的搜索方式的写法
- 二进制流读取图片
- C++学习笔记
- JPA学习--JPA中的UserTransaction的理解
- Resolved versions for app (24.2.0) and test app (23.1.1) differ