jsp 内置对象response,request,session 以及 cookie 对象的综合例子 和 include指令
来源:互联网 发布:淘宝账号异常申诉 编辑:程序博客网 时间:2024/05/16 08:05
<%@ 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对象的使用
- JS获取URL地址参数代码
- 数据库表复制
- mac安装mysql5.7
- win8.1下解决Visual C++不兼容的方法
- CAD软件查看.dwg、.dxf、.dwf、.jpeg、.jpg、.png、.gif等文件
- jsp 内置对象response,request,session 以及 cookie 对象的综合例子 和 include指令
- iOS-用两个button等分屏幕宽度的两种实现方式
- 在Visual C++下搭建OpenGL的开发环境
- Linux安装mongodb及启动
- POJ 2342. Anniversary party 简单树形DP c++ 代码
- win7 远程配置ubuntu14 python keras tensorflow 深度学习
- 进群就做题??
- 动画学习之Animate.css的使用与解析
- 使用ExtJs实现文件下载