博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Servlet中使用RequestDispatcher调派请求--include
阅读量:6800 次
发布时间:2019-06-26

本文共 2210 字,大约阅读时间需要 7 分钟。

一共有两种调派方式,一个是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...");    }}

转载地址:http://zkywl.baihongyu.com/

你可能感兴趣的文章
CentOS6.x下自动安装本地和网络YUM源
查看>>
mysql基础知识之增删查改使用介绍
查看>>
C++11 提升Vector效能的技巧
查看>>
Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask.
查看>>
docker使用指南
查看>>
如何让对方发给你需要的文件格式?
查看>>
php学习笔记--运算符号
查看>>
IPv6已分配地址中国仅占0.29%
查看>>
解决Lync2010和Lync2013转接电话断开的问题
查看>>
find grep wc awk sed sort uniq split指令详解
查看>>
高并发中的卡死状态 -HashMap
查看>>
http上传文件深度解析-高性能http传输
查看>>
Linux下配置Java环境变量
查看>>
HTTP State Management Mechanism(HTTP 状态管理机制)
查看>>
IOS之禁用UIWebView的默认交互行为
查看>>
绩效管理功能扩展包
查看>>
我的友情链接
查看>>
Android:NDK、JNI
查看>>
dl,dt,dd标记在网页中要充分利用
查看>>
Oracle非常规恢复(使用BBED跳过归档)
查看>>