java - springmvc 请求无法到达controller,出现404错误
巴扎黑
巴扎黑 2017-04-18 10:50:19
0
8
556

springmvc 请求无法到达controller,出现404错误

web.xml

<?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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>testmvc</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>
  
  <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:springmvc-servlet.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>
  
    <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>

springmvc-servlet.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.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
    <mvc:annotation-driven />
    <context:component-scan base-package="com.iszhmj.controller" />
    
     
    <bean id="viewResolver" 
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/">
            </property>
            <property name="suffix" value=".jsp">
            </property>
    </bean>
    

</beans>

WelcomeController.java

package com.iszhmj.controller;

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

@Controller
@RequestMapping("/welcome")
public class WelcomeController {
    
    @RequestMapping("/test")
    public String index()
    {
        System.out.println("index");
        return "index";
    }

}

巴扎黑
巴扎黑

모든 응답(8)
左手右手慢动作

Spring-MVC의 디버그 로그에 들어가서 살펴보세요!

PHPzhong

그럼 방문하신 URL은 어떻게 작성되어 있나요?

小葫芦

모든 웹 개발자에게 http 프로토콜을 읽어볼 것을 권장합니다

左手右手慢动作

Springmvc-servlet.xml은 src 아래에 위치해야겠죠?

阿神

제 블로그 http://blog.csdn.net/yege2006을 확인해 보세요...

洪涛

구성 파일에 <context:annotation-config/>을 추가하고

을 시도해 보세요.
阿神

이 구성에 따르면 <param-value>classpath:springmvc-servlet.xml</param-value> springmvc-servlet.xml 파일은 src 디렉터리에 있어야 합니다. 귀하의 프로젝트가 성공적으로 시작될 수 있다고 확신하시나요? ?

迷茫

src 아래에 위치해야 합니다

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!