1

ここで他の回答をできる限り調べましたが、私の問題に正確に適合する/問題を解決するものはないようです。基本的に、インデックスから ownGames にアクセスしようとすると、上記のエラーが発生します。

マッピングが正しく行われたように感じますが、明らかにそうではありません。そのため、ここに関連性のあると思われるファイルを投稿します。

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>

ゲームコントローラ

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";
    }

}

どこかに欠けている愚かな構文エラーだと確信していますが、私はSpringを初めて使用し(今日始めたばかりです)、自分が何をしているのかほとんどわかりません。助けてくれてありがとう!

4

2 に答える 2

0

href で絶対パスを使用しているため、そこで完全なパスを指定する
か、代わりに相対パスを使用する必要があります (href の先頭に / を追加)

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

また、コントローラーに追加method = RequestMethod.GETしてみてください。

URL の構造がよくわかりません。

于 2012-07-11T06:40:35.260 に答える