web.xml配置
SpringMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
SpringMVC
/
springmvc.xml配置
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-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!-- scan the package and the sub package -->
<context:component-scan base-package="test.springmvc.demo"/>
<!-- don't handle the static resource -->
<mvc:default-servlet-handler />
<!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven />
<!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
Hello.java
package test.springmvc.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Hello {
@RequestMapping("/helloworld")
public String hello(){
return "hello";
}
}
输入http://localhost:8080/SpringTest/helloword/出现404问题
不知道你这里写错了,还是输入就写错了,@RequestMapping("/**helloworld**")和你输入的不一样(http://localhost:8080/SpringTest/**helloword**/),word和world可不一样,你看是不是这个问题
问题不是很清晰,404有很多问题可以造成,可能是你tomcat没配置好,或者你的环境有问题。个人建议下载一个SpringMVC入门级项目,跑起来自己好好了解一下相关配置以及项目加载顺序,这样会比较清晰
return "hello";前加一个打印“test"测试一下是不是没有访问到路径的原因