一共有两种调派方式,一个是include用于包含进来,一个是forward,是转发出去。

这时先测试包含的include方式。

Some.java:

package cc.openhome;

import java.io.IOException;
import java.io.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Some
 */
@WebServlet("/some.view")
public class Some extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Some() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter out = response.getWriter();
        out.println("Some do one...");
        RequestDispatcher dispatcher = request.getRequestDispatcher("other.view");
        dispatcher.include(request, response);
        out.println("Some do tow...");
        out.close();
    }

}

OtherServlet.java:

package cc.openhome;

import java.io.IOException;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class OtherServlet
 */
@WebServlet("/other.view")
public class OtherServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public OtherServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter out = response.getWriter();
        out.println("Other do one...");
    }

}

Servlet中使用RequestDispatcher调派请求--include的更多相关文章

  1. Servlet中使用RequestDispatcher调派请求--forware

    顺便演示了MVC的作法,以后hello.view可以移交到jsp中处理. 而MODEL和CONTROL,VIEW就实现了分享. HelloModel.java: package cc.openhome ...

  2. Java EE javax.servlet中的RequestDispatcher接口

    RequestDispatcher接口 public interface RequestDispatcher 一.介绍 定义一个对象,从客户端接收请求并将其发送到服务器上的任何资源(例如servlet ...

  3. 【Servlet】—在servlet中常混的请求路径

    在页面请求,后台获取相关请求路径是,自己长搞混的几个路径,再次做次标记,不要每次使用想不起来是,都去写一个小的demo来测试. request.getContextPath(); request.ge ...

  4. servlet中如何发送ajax请求并动态拼接数据到html中

    废话不多说,直接上代码 1.servlet 2.js 3.jsp 有不懂得欢迎来扣我哦^_^ 详细介绍请查看全文:https://cnblogs.com/qianzf/ 原文博客的链接地址:https ...

  5. Servlet中的一些注意事项

    servlet中的一些注意事项 1 什么是servlet? 1)Servlet是Sun公司制定的一套技术标准,包含与Web应用相关的一系列接口,是Web应用实现方式的宏观解决方案.而具体的Servle ...

  6. Servlet中的请求转发RequestDispatcher接口的forword与Include的区别

    RequestDispatcher接口中具有两个方法: forward() 与 include() 均 可完成请求 的转发.区别如下: forword(): 使用该方法,则当前 的 Servlet 中 ...

  7. Servlet中的请求包含

    public class SrcIncludeServlet extends HttpServlet { public void doGet(HttpServletRequest request, H ...

  8. servlet中请求转发(forword)与重定向(sendredirect)的区别

    摘自:http://www.cnblogs.com/CodeGuy/archive/2012/02/13/2349970.html 通俗易懂 servlet请求转发与重定向的区别: request.s ...

  9. jsp/servlet 中sendRedirect,include,forward区别

    1 sendRedirect response.sendRedirect(); 服务器根据逻辑,发送一个状态码,告诉浏览器重新去请求新的地址,一般来说浏览器会用刚才请求的所有参数重新请求,所以sess ...

随机推荐

  1. 关于二分查找 使用 lower_bound

    在寻找单调递增最长自序列 , 的时候能不能确认出来哪个是单调递增最长自序列  ?  我的想法是 if(location>=num) dp[location]=b; 这样的 , 基于http:// ...

  2. 汇编程序45:检测点13.2 (loop指令的中断例程)

    安装程序: assume cs:code //loop指令的替代实现 code segment start: mov ax,cs mov ds,ax mov si,offset sub1 mov ax ...

  3. Linq学习(五)-多表连接

    本将主要介绍 内连接与 外连接 1.join Linq to sql from a in Blog_Users join b in Blog_UserInfo on a.UserId equals b ...

  4. MVC系列学习(零)-本次学习可能会遇到的问题汇总

    1.命名空间"System.Web"中不存在类型或命名空间名称"Optimization"(是否缺少程序集引用?) 在 区域学习(十六),遇到了个错误,如下 解 ...

  5. C#学习-程序集和反射

    准备项目 1.新建一个空的解决方案MyProj.sln 2.在该解决方案下,建一个控制台项目P01.csproj 3.在该项目下,自己新建一个类MyFirstClass.cs 查看解决方案MyProj ...

  6. Product Device Lot

    Product是指产品: 这个Product可以在不同的设备类型上生产, 同一类型的设备也可能硬件有差异,所以会有相对应的Device(Recipe): 同一Product(或同一Device)由于数 ...

  7. 使用adb命令提示端口被占用

    图是我的65535端口被占用了,一般adb默认使用的是5037端口##方式一   5037为adb默认端口,若5037端口被占用,查看占用端口的进程(使用命令netstat -aon|findstr ...

  8. Canvas——基本入门

    基本概念 1.canvas 是 HTML5 提供的一个用于展示绘图效果的标签. canvas 原意画布, 帆布. 在 HTML 页面中用于展示绘图效果. 最早 canvas 是苹果提出的一个方案, 今 ...

  9. 170925_1 Python socket 创建TCP的服务器端和客户端

    [Python版本]3.6 [遇到的问题] 客户端和服务器端都遇到:TypeError: a bytes-like object is required, not 'str' [解决方案] 参考:ht ...

  10. ELK基本统计图表

    ELK基本统计图表,现在基本在用自带的功能,复杂的功能还需要去摸索了