找不到Spring MVC页面
我是Spring框架的新手,尤其是Spring MVC 我正在编写一个代码,它在表单中接受一个名称并将其显示在页面上。因此index.jsp是表单类,在该类中,点击sayHello按钮时,请求应被转发到另一个页面hello.jsp并打印消息。但是点击这个按钮就会出现404错误。据我所知,所有的名称和配置都很好,但它只是不去打印信息 index.jsp找不到Spring MVC页面,spring,spring-mvc,Spring,Spring Mvc,我是Spring框架的新手,尤其是Spring MVC 我正在编写一个代码,它在表单中接受一个名称并将其显示在页面上。因此index.jsp是表单类,在该类中,点击sayHello按钮时,请求应被转发到另一个页面hello.jsp并打印消息。但是点击这个按钮就会出现404错误。据我所知,所有的名称和配置都很好,但它只是不去打印信息 index.jsp <h2>Form</h2> <form action="./hello.html"> Name: <in
<h2>Form</h2>
<form action="./hello.html">
Name: <input type="text" name="name"/><br>
<input type="submit" value="sayHello"/>
</form>
helloworld-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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
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">
<mvc:annotation-driven/>
<context:component-scan base-package="com.spring.mvc.controllers" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
hello.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>
在此处插入标题
${message}
查看您的目录
确保您有所需jar文件的构建路径
如果它是正确的,它应该工作问题得到解决。
我认为问题在于我的系统或eclipse本身。
在另一台机器上运行了代码,它运行得很好。
谢谢你回复@alex.b这应该是一个评论,而不是一个回答。对,这确实很烦人。我建议你。
<?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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
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">
<mvc:annotation-driven/>
<context:component-scan base-package="com.spring.mvc.controllers" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>