在名称为'dispatcher'的DispatcherServlet中找不到带有URI [/st/test.htm]的HTTP请求的映射 [英] No mapping found for HTTP request with URI [/st/test.htm] in DispatcherServlet with name 'dispatcher'

查看:93
本文介绍了在名称为'dispatcher'的DispatcherServlet中找不到带有URI [/st/test.htm]的HTTP请求的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试spring框架,并且是它的新手. 使用nebeans在我的spring应用程序中获取以下日志

I am trying spring framework and am new to it. Getting following logs in my spring application with nebeans

Nov 27, 2012 8:20:16 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/st/test.htm] in DispatcherServlet with name 'dispatcher'

我使用netbeans创建了应用程序,它为我创建了所有默认配置,如下所示.

I created the application using netbeans and it created all default config for me as follows.

dispatcher-servlet

dispatcher-servlet

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

    <!--
    Most controllers will use the ControllerClassNameHandlerMapping above, but
    for the index controller we are using ParameterizableViewController, so we must
    define an explicit mapping for it.
    -->
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="index.htm">indexController</prop>
            </props>
        </property>
    </bean>

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

    <!--
    The index controller.
    -->
    <bean name="indexController"
          class="org.springframework.web.servlet.mvc.ParameterizableViewController"
          p:viewName="index" />

</beans>


应用程序上下文


Application-context

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <!--bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/jdbc.properties" />

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.url}"
    p:username="${jdbc.username}"
    p:password="${jdbc.password}" /-->

    <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->

</beans>

我的控制器(默认为,(src文件夹为root))

My controller (in default package , (src folder root))

@Controller
@RequestMapping(value="test")
public class TstCnt {


    public String tst(){
        return "aks";
    }
}


网址匹配

http://localhost:8084/st/test.htm

推荐答案

尝试将控制器映射更改为此:

Try changing the controller mapping to this :

 @Controller
 @RequestMapping("/st")
 public class TstCnt {

 @RequestMapping(value = "/test", method = RequestMethod.GET)      
 public String tst(){
     return "test";
   }
 }

并确保web.xml包含这样的Dispatcher servlet的映射:

And make sure that web.xml contains the mapping for the Dispatcher servlet like this :

<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping> 

这篇关于在名称为'dispatcher'的DispatcherServlet中找不到带有URI [/st/test.htm]的HTTP请求的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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