博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
web 后端
阅读量:4488 次
发布时间:2019-06-08

本文共 3120 字,大约阅读时间需要 10 分钟。

jsp一共有九大内置对象

  1. out
  2. request
  3. response
  4. session
  5. application
  6. page
  7. pagecontext
  8. exception
  9. config

这里写图片描述

1.out

这里写图片描述

  • out.println()像客户端打印
  • out.flush()讲缓冲区内容输出到客户端
  • out.clear()清除缓冲区内容,在flush之后会异常
  • out.cleatBuffer()清除,但是不会抛出异常
  • void.close()关闭输出流

    2.requset

    这里写图片描述

3.response

这里写图片描述

请求转发与请求重定向

这里写图片描述

4. session

这里写图片描述

这里写图片描述

5.application

这里写图片描述

这里写图片描述

jsp内置对象实例,实现用户登录

//login.jsp<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%   String path = request.getContextPath();   String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>            
imooc - Login

//dologin.jsp<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%  String path = request.getContextPath();  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  String username ="";  String password ="";  request.setCharacterEncoding("utf-8");//防止中文乱码  username = request.getParameter("username");  password = request.getParameter("password");  //如果用户和密码都等于admin,则登录成功  if("admin".equals(username)&&"admin".equals(password))  {     session.setAttribute("loginUser", username);     request.getRequestDispatcher("login_success.jsp").forward(request, response);     //服务器内部转发 用requset  }  else  {//失败 请求重定向     response.sendRedirect("login_failure.jsp");  }%>
//login_success.jsp<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%   String path = request.getContextPath();   String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>            
imooc - Login
<% String loginUser = ""; if(session.getAttribute("loginUser")!=null) { loginUser = session.getAttribute("loginUser").toString(); //session.getAttribute返回次对话中的指定名称绑定在一起的对象,若没有折返回null } %> 欢迎您
<%=loginUser%>,登录成功!
login_failure.jsp@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%   String path = request.getContextPath();   String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>            
imooc - Login
登录失败!请检查用户或者密码!
返回登录

这里写图片描述

这里写图片描述

这里写图片描述

转载于:https://www.cnblogs.com/oifengo/p/9385967.html

你可能感兴趣的文章
WINDOWS API 大全(一)
查看>>
Wmic
查看>>
WINDOWS API 大全(二)
查看>>
SetWindowsHookEx失败
查看>>
C/C++判断字符串是否包含某个字符串
查看>>
[C#菜鸟]C# Hook
查看>>
easyhook源码分析二——注入
查看>>
C#调用C++的库 P/Invoke工具集
查看>>
easyhook源码分析三——申请钩子
查看>>
easyhook源码分析一
查看>>
对“XXX::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们...
查看>>
VC中MessageBox与AfxMessageBox用法与区别
查看>>
Web开发使用jsTree实例
查看>>
JDK的安装和Java环境变量配置
查看>>
常用内置模块(二)--logging、hashlib、shelve、xml、configparser
查看>>
6/20晚学习状态
查看>>
前台提交数据到node服务器(post方式)
查看>>
sequelize模型
查看>>
处理器体系结构
查看>>
全局变量和局部变量
查看>>