我正在尝试一个简单的Spring-MVC应用程序,它从用户那里获取输入并在屏幕上显示它。我是Spring-MVC的新手。我在浏览器上收到消息说:
"HTTP status 404:The requested resource is not available"
我正在尝试使用网址在浏览器上运行:
"http://localhost:8080/Spring_Test/admissionForm.html"
它没有在eclipse控制台上显示任何消息。我不确定天气我缺少任何jar文件或其他东西。在这里,我分享我的文件内容和jar文件。请帮我解决这个问题。
Jar文件:
commons-fileupload-1.2.2.jar
commons-io-1.3.2.jar
commons-logging-1.1.1.jar
jstl-1.1.2.jar
mysql-connector-java-5.1.34-bin.jar
spring-aop-3.0.6.RELEASE.jar
spring-asm-3.0.6.RELEASE.jar
spring-beans-3.0.6.RELEASE.jar
spring-context-3.0.6.RELEASE.jar
spring-context-support-3.0.6.RELEASE.jar
spring-core-3.0.6.RELEASE.jar
spring-expression-3.0.6.RELEASE.jar
spring-jdbc-3.2.9.RELEASE.jar
spring-web-3.0.6.RELEASE.jar
spring-webmvc-3.0.6.RELEASE.jar
的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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Spring_Test</display-name>
<servlet>
<servlet-name>Spring_Test</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring_Test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Spring_Test-servlet.xml中:
<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.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">
<context:component-scan base-package="com.leader" />
<mvc:default-servlet-handler/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
控制器:
package com.leader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.*;
@Controller
public class StudentAdmissionController {
@RequestMapping(value="/Spring_Test/admissionForm.html", method=RequestMethod.GET)
public ModelAndView getAdmissionForm(){
ModelAndView model = new ModelAndView("AdmissionForm");
return model;
}
@RequestMapping(value = "/Spring_Test/submitAdmissionForm.html", method = RequestMethod.POST)
public ModelAndView submitAdmissionForm(@RequestParam("studentName") String name,@RequestParam("hobby") String hobby){
ModelAndView model = new ModelAndView("AdmissionSuccess");
model.addObject("msg", "hello");
return model;
}
}
答案 0 :(得分:1)
也许您在配置中忘记了<mvc:annotation-driven />
以启用@Controller注释扫描,至少是它的样子
答案 1 :(得分:0)
@RequestMapping(value =“/ admissionForm.html”,method = RequestMethod.GET) 而不是在你的控制器中使用
@RequestMapping(value =“/ Spring_Test / admissionForm.html”,method = RequestMethod.GET)
答案 2 :(得分:0)
尝试将web.xml中的url模式更改为/ *而不是/