jsp页面跳转方式

    xiaoxiao2021-12-14  22

    一.response.setRedirect()

    response.sendRedirect("/index.jsp");

    二. RequestDispatcher.forward()

     public void doPost(HttpServletRequest request,HttpServletResponse response)    throws ServletException,IOException{   response.setContentType("text/html; charset=gb2312");   ServletContext sc = getServletContext();   RequestDispatcher rd = null;   rd = sc.getRequestDispatcher("/index.jsp"); //定向的页面   rd.forward(request, response);   }

    三.<jsp:forward page=”” /> 它的底层部分是由RequestDispatcher来实现的,因此它带有RequestDispatcher.forward()方法的印记。   如果在之前有很多输出,前面的输出已使缓冲区满,将自动输出到客户端,那么该语句将不起作用,这一点应该特别注意。   注意:它不能改变浏览器地址,刷新的话会导致重复提交

    四.修改HTTP header的Location属性来重定向

    <%   response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);   String newLocn = "/newpath/jsa.jsp";   response.setHeader("Location",newLocn);   %>

    五.标签跳转

    <meta http-equiv="refresh" content="300; url=target.jsp"
    转载请注明原文地址: https://ju.6miu.com/read-968550.html

    最新回复(0)