zoukankan      html  css  js  c++  java
  • 请求转发和重定向

    请求转发和重定向
    HttpServletRequest request,HttpServletResponse response
    一、
    1.
    /**
    *请求转发
    *将请求转发请求转发到另一资源;
    *此过程依然在同一个请求范围内;
    *浏览器地址栏内容不变。
    */

    request.setAttribute("messsage","hello");
    request.getRequestDispatcher("path").forword();

    2.
    /**
    *重定向
    *将页面重新定向到一个新地址;
    *之前的请求失效,进入一个新的请求;
    *跳转后浏览器地址栏的内容将变成新的地址。
    */
    response.sendRedirect(path);

    二.
    1.request 作用域 一次请求
    2.session 作用域 一个会话
    3.application 作用域 应用启动直到结束
    1.
    HttpServletRequest的方法
    public void setAttribute(String name, Object obj)
    public Object getAttribute(String name)
    public Enumeration getAttributeNames()
    public void removeAttribute(String name)

    2.HttpSession的方法
    public void setAttribute(String name, Object obj)
    public Object getAttribute(String name)
    public Enumeration getAttributeNames()
    public void removeAttribute(String name)

    3.使用ServletContext对象存储数据
    ServletContext context = this.getServletContext();
    或ServletContext context = this.getServletConfig().getServletContext();
    context. setAttribute(“score”,score);

    int score=(Integer) application. getAttribute(“score”);

    ServletContext的方法
    public void setAttribute(String name, Object obj)
    public Object getAttribute(String name)
    public Enumeration getAttributeNames()
    public void removeAttribute(String name)

  • 相关阅读:
    SharePoint 2013 APP 开发示例 (六)服务端跨域访问 Web Service (REST API)
    麦咖啡导致电脑不能上网
    SharePoint 2013 Central Admin 不能打开
    SharePoint 2013 APP 开发示例 (五)跨域访问 Web Service (REST API)
    SharePoint 2013 APP 开发示例 系列
    synthesize(合成) keyword in IOS
    Git Cmd
    简单的正则匹配
    Dropbox
    SQL Server Replication
  • 原文地址:https://www.cnblogs.com/mznsndy/p/11646997.html
Copyright © 2011-2022 走看看