开发者社区> 问答> 正文

SpringMVC配置问题 热-JAVA报错

"

首先是web.xml

<servlet>

<servlet-name>spring</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

 

<servlet-mapping>

<servlet-name>spring</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

然后是

<?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:context="http://www.springframework.org/schema/context"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="

        http://www.springframework.org/schema/beans 

        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

        http://www.springframework.org/schema/context 

        http://www.springframework.org/schema/context/spring-context-3.0.xsd

        http://www.springframework.org/schema/mvc 

        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd

        ">

        <mvc:annotation-driven/>

       <context:component-scan base-package="com.zpl.controller.*"></context:component-scan>

       

        <bean id="viewResolver"

          class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/jsp/"/>

        <property name="suffix" value=".jsp"/>

       </bean>

</beans>

最后是

package com.zpl.controller;

 

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

 

@Controller

public class HellowController {

 

@RequestMapping(value="/hello")

public String hello(){

System.out.println("hello");

return "hello";

}

}

运行的http://localhost:8080/项目/hello

No mapping found for HTTP request with URI [/spring_mvc/hello] in DispatcherServlet with name 'spring'


"

展开
收起
montos 2020-06-01 21:21:01 529 0
1 条回答
写回答
取消 提交回答
  • "

    首先是web.xml

    <servlet>

    <servlet-name>spring</servlet-name>

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

     

    <servlet-mapping>

    <servlet-name>spring</servlet-name>

    <url-pattern>/</url-pattern>

    </servlet-mapping>

    然后是

    <?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:context="http://www.springframework.org/schema/context"

        xmlns:mvc="http://www.springframework.org/schema/mvc"

        xsi:schemaLocation="

            http://www.springframework.org/schema/beans 

            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

            http://www.springframework.org/schema/context 

            http://www.springframework.org/schema/context/spring-context-3.0.xsd

            http://www.springframework.org/schema/mvc 

            http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd

            ">

            <mvc:annotation-driven/>

           <context:component-scan base-package="com.zpl.controller.*"></context:component-scan>

           

            <bean id="viewResolver"

              class="org.springframework.web.servlet.view.InternalResourceViewResolver">

            <property name="prefix" value="/WEB-INF/jsp/"/>

            <property name="suffix" value=".jsp"/>

           </bean>

    </beans>

    最后是

    package com.zpl.controller;

     

    import org.springframework.stereotype.Controller;

    import org.springframework.web.bind.annotation.RequestMapping;

     

    @Controller

    public class HellowController {

     

    @RequestMapping(value="/hello")

    public String hello(){

    System.out.println("hello");

    return "hello";

    }

    }

    运行的http://localhost:8080/项目/hello

    No mapping found for HTTP request with URI [/spring_mvc/hello] in DispatcherServlet with name 'spring'


    "
    2020-06-01 21:21:23
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载