您的位置:首页技术文章
文章详情页

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

【字号: 日期:2024-01-25 10:56:29浏览:40作者:猪猪

问题描述

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' 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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd'><mvc:annotation-driven /> <context:component-scan base-package='com.iszhmj.controller' /> <bean 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'; }}

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

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

问题解答

回答1:

把Spring-MVC的debug日志输入来看看!

回答2:

所以你访问的url是怎么写的呢?

回答3:

推荐所有web开发者通读一下http协议

回答4:

springmvc-servlet.xml要放在src下吧?

回答5:

看下我的博客吧 http://blog.csdn.net/yege2006...

回答6:

配置文件里添加<context:annotation-config/>试试

回答7:

按照这个配置 <param-value>classpath:springmvc-servlet.xml</param-value> springmvc-servlet.xml文件需要放在src目录下。 然后你确定你的项目可以启动成功??

回答8:

应该是放在src下面的

标签: java
相关文章: