找不到HTTP请求的映射 [英] No mapping found for HTTP request

查看:196
本文介绍了找不到HTTP请求的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我回来在Springs工作.我曾经在Springs工作,但盲目地了解得并不多.我曾经遇到过很多错误,非常基本的错误,而我又得到了它们.

I am back with working in Springs. I used to work in Springs but blindly, didn't understand much. I used to get a lot of errors, very basic ones, and I am getting them again.

我的问题是,我不知道Spring-MVC的配置如何工作.
当我从STS运行项目时会发生什么?
我正在STS的spring模板项目中工作.

My problem is that, I don't know how the configuration of the Spring-MVC work.
What happens when I run the project from my STS?
I am working on the spring template project in STS.

我在运行项目时得到了这个.
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/common/] in DispatcherServlet with name 'appServlet'

I am getting this when I run the project.
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/common/] in DispatcherServlet with name 'appServlet'

我完全受够了,坏了.
刚休息两个月,我又回到了起跑线上.

I am totally fed up and broken.
Just 2 months of break from work, I am back at the starting block.

我不想发布我的代码并使问题具体化.

I don't want to post my code and make the question specific.

我想要一个解释服务器执行spring项目的方式的答案.从运行应用程序(基本hello world应用程序)一直到显示主页.
这将对所有初学者都有帮助.
我尝试在网上搜索这样的解释,但没有得到任何适当的解释,但有很多基本示例.这些样本很容易理解,但并不能解释服务器的运行方式.

I want an answer that explains the way in which the server executes a spring project. Right from the running of an application(basic hello world application) to the display of the home page.
This will be helpful for all the beginners.
I tried searching for such an explanation in the net but I didn't get any proper explanation, but got a lot of basic samples. Those samples are easy to understand but are not explaining the way in which the server goes about.

注意:我正在寻找一个解释Springs概念的答案.从运行应用程序到显示主页.在此过程中会发生什么?服务器从哪里开始?怎么回事?

Note: I am looking for an answer that explains the Springs concept. From the running of an application to the display of a home page. What all happens in this process? Where does the server start with? How does it go about?

推荐答案

这是最初servlet容器加载web.xml文件的流程.在web.xml中,我们将指定所有请求均由spring FrontController处理,即DispatcherServlet. 我们通过添加以下代码来包含它

Here is the flow initially servlet container loads the web.xml file.In web.xml we will specify that all the requests are handled by the spring FrontController that is DispatcherServlet. We include it by adding the following code

<servlet>
        <servlet-name>dispatcher</servlet-name>
         <servletclass>org.springframework.web.servlet.DispatcherServlet</servletclass>
         <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

此处指示url请求是否为* .htm,由dispatcherServlet处理,然后由dispatcherServlet加载dispatcher-servlet.xml.我们需要通过编写特定的url请求(例如

Here it indicate if the url request is of *.htm it is handled by dispatcherServlet then dispatcherServlet load dispatcher-servlet.xml . Where we need to mention the mapping to controller by writing the specific url request such as

<bean name="/insert.htm" class="com.controller.MyController"></bean>

因此在bean中我们提到对于/insert.htm的请求,它告诉servlet查看所提到的类.您需要在ex方法上方使用@RequestMapping的注释

So in bean we mention that for request of /insert.htm it tells the servlet to look in the mentioned class.You need use the Annotation of @RequestMapping above the method for ex

@RequestMapping("/insert.htm")
public ModelAndView insert(HttpServletRequest req,Student student)
{
   String name=req.getParameter("name");
    int id=Integer.parseInt(req.getParameter("id"));
    student.setId(id);

    return new ModelAndView("display","Student",student);//It returns a view named        display with modelclass name as `Student` and model object student
    }

因此,当出现/insert.htm的请求URL时,它执行上述方法,它返回ModelAndView对象,只返回一个视图.它再次转到dispatcher-servlet.xml并查找视图解析器以添加将要添加的常规代码是

So when a Request url of /insert.htm appears it executes the above method it returns a ModelAndView object nothing but an view.It again goes to dispatcher-servlet.xml and looks for view Resolver the normal code that is to be added is

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />

因此从中获取逻辑视图名称,并在其后附加前缀和后缀.最后,它在视图中显示内容.因此,它在视图解析器前缀中查找显示并后缀事物,最后返回/WEB-INF/jsp/display.jsp.其中显示jsp内容

So from this it gets the logical view name and appends the prefix and suffix to it .Finally it displays the content in the view.so it looks for display in view resolver prefixes and suffixes the things and finally returns /WEB-INF/jsp/display.jsp .Which displays the jsp content

这篇关于找不到HTTP请求的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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