java吧 关注:1,251,192贴子:12,737,250
  • 3回复贴,共1

求教:spring 问题

只看楼主收藏回复

web.xml


1楼2016-01-05 12:02回复
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <error-page>
    <error-code>404</error-code>
    <location>/404.html</location>
    </error-page>
    <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:/config/spring-mvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    <display-name>mvc</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    </web-app>


    2楼2016-01-05 12:03
    回复
      *:/config/spring-mvc-config.xml
      <?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: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.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
      <context:annotation-config/>
      <context:component-scan base-package="mv.action"/>
      <mvc:annotation-driven></mvc:annotation-driven>
      <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/views/"></property>
      <property name="suffix" value=".jsp"></property>
      </bean>
      </beans>


      3楼2016-01-05 12:04
      回复
        import org.springframework.stereotype.Controller;
        import org.springframework.web.bind.annotation.RequestMapping;
        @Controller
        public class Test {
        @RequestMapping(value="/index")
        public String indexTest(){
        return "index";
        }
        }
        输入http://localhost:8080/mvc/index
        老是报一月 05, 2016 12:10:56 下午 org.springframework.web.servlet.PageNotFound noHandlerFound
        警告: No mapping found for HTTP request with URI [/mvc/index] in DispatcherServlet with name 'springmvc'
        求大神帮忙


        6楼2016-01-05 12:13
        回复