zoukankan      html  css  js  c++  java
  • (十二)会话跟踪技术之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界面也无法输出。
  • 相关阅读:
    gcvt(),ecvt(),fcvt()的区别
    SQLITE3 使用总结
    C++的类型转换浅析
    JAVA Class21
    JAVA Class20
    JAVA Class19
    JAVA Class18
    JAVA Class17
    JAVA Class16
    关于hover失效问题(!important)
  • 原文地址:https://www.cnblogs.com/shyroke/p/6492708.html
Copyright © 2011-2022 走看看