2013-08-02 64 views
0

我收到了没有找到调度程序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文件和搜索模式。

+0

您可以搜索“映射到URL”,以检查其控制器映射到您的特定网址? – Hippoom

+0

你能更详细地解释我吗?我对春天MVC很陌生。当我部署应用程序时,初始主页本身并未加载。 –

+0

将日志级别设置为DEBUG,然后检查日志。有没有像“Mapped”{[/ payRoyalties],......}任何行到公共java.lang.String SearchController .searchJobs(org.springframework.ui.Model)...“当您启动服务器? – Hippoom

回答

1

在您的班级中没有名为search的映射。

您需要您的getSearch()方法

+0

主页方法指向search.jsp页面 –

+0

有一件事情,处理程序与jsp名称无关,您可以将您的jsp重命名为任何内容并更改getSearch中的返回值方法。您在其中一个方法中添加了'@ModelAttribute(“search”)',这用于您的处理程序中,在其中一个方法参数上添加了相同的注释。 – varun

0

增加@RequestMapping(值= “/搜索”),我认为问题出在你的web servlet配置。之前我曾看到过这种情况,当时Spring将映射URL与映射到JSP文件之间混淆了。

总之,而不是:

<servlet-mapping> 
    <servlet-name>mvc-dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

你应该尝试:

<servlet-mapping> 
    <servlet-name>mvc-dispatcher</servlet-name> 
    <url-pattern>/*.html</url-pattern> 
</servlet-mapping> 

然后尝试用/payRoyalties.html

+0

感谢您的回复,但是当我更改为此应用程序未能部署。 –

+0

LOG:重度:甲子容器开始 java.util.concurrent.ExecutionException期间失败:org.apache.catalina.LifecycleException:未能启动成分[StandardEngine [卡塔利娜] .StandardHost [本地主机] .StandardContext [/ EnhancedRoyaltyTool]] –

+0

@SandeepRao:它不应该失败。其他地方一定有问题,你能否给我提供完整的堆栈跟踪? –

0
@ModelAttribute("search") 
public Search getSearch() 
{ 
    return new Search(); 
} 

访问控制器上面代码的部分是混乱的,你有@ModelAttribute中的“搜索”,而@RequestMapping没有“搜索”,什么你是否想要这样做。

请提供日志以获取更多帮助。

+0

2013年8月2日上午08时51分23秒org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:否的DispatcherServlet找到HTTP请求与URI [/ EnhancedRoyaltyTool /]名为“MVC的调度”映射 –

+0

@ModelAttribute搜索直接在search.jsp页面中使用。我的理解是,当你的search.jsp加载它时会自动绑定调用getSearch方法并将它绑定到jsp页面中的搜索对象。 –

+0

是的,我错过了你有搜索作为您的处理方法之一定义的模型,这似乎很好。这个问题看起来非常明显,它表示“在DispatcherServlet中没有找到具有URI [/ EnhancedRoyaltyTool /]的HTTP请求的映射,这意味着你需要有一个映射到这个URL的处理方法,像'@RequestMapping(”/ EnhancedRoyaltyTool“)' 。希望这是唯一的错误 – varun

0

你想这样的:

@Controller 
@RequestMapping("/search") 
public class SearchController { 
    … 
} 
+0

我不认为,这是问题所在。因为他没有访问url/search“,请参阅标签”action =“payRoyalties”,并且已经为此定义了映射。日志会清除更多的东西。 – varun

相关问题