我收到了沒有找到調度程序servelt的映射。你能否指出我在代碼中的問題所在。我很新的Spring MVC的未在春季爲HTTP請求找到映射mvc
我的錯誤是(我的POM具有EnhancedRoyaltyTool的的artifactId)
No mapping found for HTTP request with URI [/EnhancedRoyaltyTool/] in DispatcherServlet with name 'mvc-dispatcher
我的web.xml文件
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Web MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- <listener> -->
<!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> -->
<!-- </listener> -->
</web-app>
我的MVC-調度員的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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.acxiom.saas.royalty.controller"/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
我Controller文件
@Controller
public class SearchController
{
@ModelAttribute("search")
public Search getSearch()
{
return new Search();
}
@RequestMapping(value ="/")
public String homePage()
{
System.out.println("home");
return "search";
}
@RequestMapping(value ="/payRoyalties", method = RequestMethod.POST)
public String searchJobs(ModelMap model, @ModelAttribute("search") Search search)
{
System.out.println(search.getOesNumber() +"TEST");
model.addAttribute("test", "testing modelmap");
return "payRoyalties";
}
}
我search.jsp的文件
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!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>Search For Jobs</title>
</head>
<body>
<form:form method="POST" modelAttribute="search" action="payRoyalties" >
<table>
<tr>
<td><form:label path="oesNumber">OES Number</form:label></td>
<td><form:input path="oesNumber" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Search" /></td>
</tr>
</table>
</form:form>
</body>
</html>
我有一個payRoyalties.jsp文件和搜索模式。
您可以搜索「映射到URL」,以檢查其控制器映射到您的特定網址? – Hippoom
你能更詳細地解釋我嗎?我對春天MVC很陌生。當我部署應用程序時,初始主頁本身並未加載。 –
將日誌級別設置爲DEBUG,然後檢查日誌。有沒有像「Mapped」{[/ payRoyalties],......}任何行到公共java.lang.String SearchController .searchJobs(org.springframework.ui.Model)...「當您啓動服務器? – Hippoom