春天3.2.0没有发现uri

时间:2014-08-25 12:45:57

标签: java javascript

以下是:

appServlet-servlet.xml中

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


    <!-- DispatcherServlet Context: defines this servlet's request-processing 
        infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <!-- <annotation-driven /> -->
    <!--  <context:annotation-config /> -->

      <mvc:annotation-driven />
    <context:component-scan base-package="com.interlace"/>


</beans:beans>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" >




<servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>




</web-app>

HelloController.java

@Controller
@RequestMapping("/welcome")
public class HelloController  {

    @RequestMapping("/hello")
    public ModelAndView helloWorld(HttpServletRequest arg0,
            HttpServletResponse arg1) throws Exception {
        return new ModelAndView("/HelloWorld.jsp");
    }

}

在DispatcherServlet中找不到带有URI [/ HelloWorld / welcome / hello]的HTTP请求的映射,名称为&#39; appServlet&#39; 我正在使用spring 3.2.0如果添加了所有必需的jar文件。我正在使用没有maven。请尝试帮助我

2 个答案:

答案 0 :(得分:0)

来自春季参考文档:

DispatcherServlet是一个实际的Servlet(它继承自HttpServlet基类), 因此在Web应用程序的web.xml中声明。您需要使用同一web.xml文件中的URL映射来映射您希望DispatcherServlet处理的请求。这是标准的Java EE Servlet配置;以下示例显示了这样的DispatcherServlet声明和映射:

<web-app>
<servlet>
    <servlet-name>example</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>example</servlet-name>
    <url-pattern>/example/*</url-pattern>
</servlet-mapping>
</web-app>

在前面的示例中,所有以/ example开头的请求都将由 DispatcherServlet实例名为example。

答案 1 :(得分:0)

从您的URI中删除HelloWorld并尝试通过/ welcome / hello访问