欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

关于springmvc报错404的问题

程序员文章站 2022-03-02 11:30:54
最近初学springmvc,做了一个简单工程实现conntroller加载,一直报错404,调试许久没找到问题,请求帮助,多谢各位了!编程环境:win10x64+eclipse+tomcat8.5文件...

最近初学springmvc,做了一个简单工程实现conntroller加载,一直报错404,调试许久没找到问题,请求帮助,多谢各位了!

编程环境:win10x64+eclipse+tomcat8.5
文件结构:

关于springmvc报错404的问题

主要代码:
web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="webapp_id" version="3.1">
<display-name>myweb</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>

<!-- 加载spring配置文件 -->
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</context-param>
<!-- spring监听 -->
<listener>
<listener-class>org.springframework.web.context.contextloaderlistener</listener-class>
</listener>
<!-- 配置springmvc -->
<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.xml</param-value>
</init-param>

<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>

<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

hellocontroller.java

package com.hello;

import org.springframework.stereotype.controller;
import org.springframework.web.bind.annotation.requestmapping;

@controller
public class hellocontroller {

@requestmapping("/success")
public string helloworld() {
system.out.println("拦截");
return "success";
}
}

springmvc.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.hello"/>

<!-- 处理静态资源 -->
<mvc:default-servlet-handler/>

<!-- 配置视图解析器 -->
<bean
class="org.springframework.web.servlet.view.internalresourceviewresolver">
<property name="prefix" value="/web-inf/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

调试图:

关于springmvc报错404的问题

关于springmvc报错404的问题

到此这篇关于关于springmvc报错404的问题的文章就介绍到这了,更多相关springmvc报错404内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!