2012-07-11 51 views
1

我已经通过其他答案查看了尽可能好的一面,但似乎完全不符合我的问题/解决方案我的问题。从本质上讲,当我尝试从我的索引访问ownedGames时,出现上述错误。警告:在名为'spring'的DispatcherServlet中找不到具有URI [/ XboxVoting/ownedGames]的HTTP请求的映射

我觉得我有正确的映射,但显然我没有。所以在这里我会发布任何看起来可能相关的文件。

的index.html(其中我点击,让错误链接)

<html> 
<head> 
    <title>xbox voting</title> 
</head> 
<body> 
    <a href="wantedGames">Vote on Games!</a> <br /> 
    <a href="ownedGames">View the Games We Own!</a> 
</body> 
</html> 

的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_2_5.xsd" 
    id="WebApp_ID" version="2.5"> 
    <display-name>Spring3-Hibernate</display-name> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 
    <servlet> 
     <servlet-name>spring</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>spring</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

为spring-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:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
     http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> 

    <context:annotation-config /> 
    <context:component-scan base-package="net.nerdery.xboxvoting.controller" /> 

    <bean id="jspViewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="/WEB-INF/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 


    <bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </bean> 
    <bean id="propertyConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
     p:location="jdbc.properties" /> 

    <bean id="dataSource" 
     class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" 
     p:driverClassName="${jdbc.driverClassName}" 
     p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" 
     p:password="${jdbc.password}" /> 


    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation"> 
      <value>hibernate.cfg.xml</value> 
     </property> 
     <property name="configurationClass"> 
      <value>org.hibernate.cfg.AnnotationConfiguration</value> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">${jdbc.dialect}</prop> 
       <prop key="hibernate.show_sql">true</prop> 
      </props> 
     </property> 
    </bean> 

    <tx:annotation-driven /> 
    <bean id="transactionManager" 
     class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 
</beans> 

GameController

package net.nerdery.xboxvoting.controller; 

import java.util.Map; 


import net.nerdery.xboxvoting.domain.Game; 
import net.nerdery.xboxvoting.service.GameService; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.validation.BindingResult; 
import org.springframework.web.bind.annotation.ModelAttribute; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
public class GameController { 

    @Autowired 
    private GameService gameService; 

    @RequestMapping("/XboxVoting/ownedGames") 
    public String listOwnedGames(Map<String, Object> map) { 
     map.put("game", new Game()); 
     map.put("ownedGamesList", gameService.listOwnedGames()); 

     return "game"; 
    } 

    @RequestMapping("/wantedGames") 
    public String listWantedGames(Map<String, Object> map) { 
     map.put("game", new Game()); 
     map.put("wantedGamesList", gameService.listOwnedGames()); 

     return "game"; 
    } 

    @RequestMapping(value = "/add", method = RequestMethod.POST) 
    public String addGame(@ModelAttribute("game") 
    Game game, BindingResult result) { 

     gameService.addGame(game); 

     return "redirect:/ownedGames"; 
    } 

} 

我敢肯定,这是我的思念某处一些无聊的语法错误,但我是新来的春天(今天刚刚开始),并几乎没有任何想法,我在做什么。所以谢谢你的帮助!

+0

你能告诉当你得到这个错误的意思是,当你点击任何URL或当你提交任何形式的?还要添加这些细节。 – xyz 2012-07-11 06:14:24

+0

基本上任何URL。我有一个包含两个链接的索引文件,ownedGames和wantedGames,并且都为该文件返回了一个No mapping found错误(即wantedGames将给出警告:在DispatcherServlet中找不到URI的HTTP请求映射)[/ XboxVoting/wantedGames]名称为'spring' – lashiel 2012-07-11 06:23:18

+0

您可以添加用于链接的HTML代码片段吗?'href'更具体。 – xyz 2012-07-11 06:25:06

回答

0

您正在使用的href绝对路径,所以你应该有指定完整路径
或而不是使用相对路径(追加/在HREF的开始)像

<a href="/wantedGames">Vote on Games!</a> <br /> 
<a href="/XboxVoting/ownedGames">View the Games We Own!</a> 

还尝试加入method = RequestMethod.GET到控制器。

我不确定你的网址结构。

+0

这将返回404。“请求的资源(/ ownedGames )是不可用的。“具体地说。 – lashiel 2012-07-11 06:42:09

+0

@ user1516707:它看起来像问题是在'href'中使用的URL。尝试几个组合。我也更新了我的答案 – xyz 2012-07-11 07:54:36

+0

几乎每个组合都可以考虑,并将requestmethod.get添加到控制器中。所有内容都提供了404或映射错误。 – lashiel 2012-07-11 17:04:17

1

你需要改变 <url-pattern>/</url-pattern><url-pattern>/*</url-pattern>

相关问题