• (十二)会话跟踪技术之servlet通信(forward和include)


    一、servlet通信方法
    二、具体应用
    • scopeServlet.java
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		response.setContentType("text/html;charset=UTF-8");
    		PrintWriter out=response.getWriter();
    		out.print("第yi个页面");
    		RequestDispatcher dis=this.getServletContext().getRequestDispatcher("/servlet/getscope");
    		dis.include(request,response);
    		out.close();
    	}
    
    
    
    •    getScopeServlet.java
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {	
    		response.setContentType("text/html;charset=UTF-8");
    		PrintWriter out=response.getWriter();
    		out.print("第er个页面");	}
    
        ps:无论是RequestDispatcher dis=this.getServletContext().getRequestDispatcher("/servlet/getscope");
    dis.include(request,response);还是request.getRequestDispatcher("getscope").forward(request,response); 都要添加forwa或者include方法,否则就不能跳转
    ps: 特别注意上文中的out.close();的位置,如果它跟在out.print("第yi个页面");的后面,则结果
    因为out流已经关闭了,即使跳转到getScopeServlet.java界面也无法输出。
  • 相关阅读:
    ST L3 测试用例
    ST L2 系统测试流程
    ST L1 软件测试基础
    软件测试 Part5 使用测试文档
    软件测试 Part4 测试的补充
    Python Day37 python多线程标准模块concurrent.futures
    Python Day36 python多线程
    Python Day35进程池,回调函数
    Python Day34 python并发编程之多进程
    Python Day32 进程
  • 原文地址:https://www.cnblogs.com/shyroke/p/6492708.html
Copyright © 2020-2023  润新知