Spring 中的 Dispatcher Servlet 是什么? [英] What is Dispatcher Servlet in Spring?

查看:27
本文介绍了Spring 中的 Dispatcher Servlet 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这张图片中(我从 here),HTTP 请求向 Dispatcher Servlet 发送一些东西. >

我的问题是Dispatcher Servlet是做什么的?

是否类似于从网页中获取信息并将其扔给控制器?

解决方案

DispatcherServlet 的工作是获取传入的 URI 并找到处理程序的正确组合(通常是 Controller 上的方法 类)和视图(通常是 JSP)组合起来形成应该在该位置找到的页面或资源.

我可能有

  • 一个文件/WEB-INF/jsp/pages/Home.jsp
  • 和一个类上的方法

    @RequestMapping(value="/pages/Home.html")私有 ModelMap buildHome() {返回一些东西;}

Dispatcher servlet 是知道"在浏览器请求页面时调用该方法并将其结果与匹配的 JSP 文件组合以生成 html 文档的部分.

实现方式因配置和 Spring 版本而异.

也没有理由最终结果必须是网页.它可以做同样的事情来定位 RMI 端点,处理 SOAP 请求,任何可以进入 servlet 的东西.

In this image (which I got from here), HTTP request sends something to Dispatcher Servlet.

My Question is what does Dispatcher Servlet do?

Is it something like getting the information thrown from the web page and throwing it to the controller?

解决方案

The job of the DispatcherServlet is to take an incoming URI and find the right combination of handlers (generally methods on Controller classes) and views (generally JSPs) that combine to form the page or resource that's supposed to be found at that location.

I might have

  • a file /WEB-INF/jsp/pages/Home.jsp
  • and a method on a class

    @RequestMapping(value="/pages/Home.html")
    private ModelMap buildHome() {
        return somestuff;
    }
    

The Dispatcher servlet is the bit that "knows" to call that method when a browser requests the page, and to combine its results with the matching JSP file to make an html document.

How it accomplishes this varies widely with configuration and Spring version.

There's also no reason the end result has to be web pages. It can do the same thing to locate RMI end points, handle SOAP requests, anything that can come into a servlet.

这篇关于Spring 中的 Dispatcher Servlet 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆