zoukankan      html  css  js  c++  java
  • Servlet跳转

    方便自己查询,嫌低级的勿喷。。。。

    在Servlet中跳转有两种:

    1.客户端跳转

    在Servlet中要进行客户端跳转(地址栏的地址信息将发生改变),直接使用HttpServletResponse接口的sendRedirect()方法,注意此跳转只能传递session及application范围的属性,而无法传递request范围的属性。

    2.服务器端跳转

    在Servlet中没有像JSP中的<jsp:forward>指令,所以如果要执行服务器端跳转(地址栏的地址信息不发生改变),就必须依靠RequestDispatcher接口完成,此接口中提供了下面两种方法:

    No 方法 描述
    1 public void forward(ServletRequest request,ServletResponse response) throws ServletException,IOException 页面跳转
    2 public void include(ServletRequest request,ServletResponse response) throws ServletException,IOException 页面包含

    使用RequestDispatcher接口的forward()方法即可完成跳转功能的实现,但是如果要想使用此接口还需要使用ServletRequest接口提供如下的方法进行实例化:

    No 方法 描述
    1 public RequestDispatcher getRequestDispatcher(String path) 取得RequestDispatcher接口实例
    package org.lxh.servletdemo ;
    import java.io.* ;
    import javax.servlet.* ;
    import javax.servlet.http.* ;
    public class ServerRedirectDemo extends HttpServlet {
        public void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
            req.getSession().setAttribute("name","李兴华") ;
            req.setAttribute("info","MLDNJAVA") ;
            RequestDispatcher rd = req.getRequestDispatcher("get_info.jsp") ;    // 准备好了跳转操作
             rd.forward(req,resp) ;    // 完成跳转
        }
        public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
            this.doGet(req,resp) ;
        }
    }
  • 相关阅读:
    从路径中拆分出文件名和后缀
    屏幕中判断必输
    根据tcode查找增强的程序
    IDOC练习(二、接收端配置)
    ORACLE 绑定变量用法总结
    Oracle数据类型之number
    总结:整理 oracle异常错误处理
    ISNUMBER函数的创建以及函数创建思路。
    oracle 绑定变量 bind variable(2)
    oracle 绑定变量(bind variable)(1)
  • 原文地址:https://www.cnblogs.com/mjsh/p/3205433.html
Copyright © 2011-2022 走看看