使用ModelAndView的Spring 3 - 404错误

时间:2013-05-16 22:07:14

标签: spring-mvc http-status-code-404 modelandview

我收到此404错误消息

The requested resource (/ghs1986/WEB-INF/pages/poll1.jsp) is not available.

来自这种控制器方法。

@RequestMapping(value = "/poll1", method = RequestMethod.POST)
public ModelAndView processPoll1(@RequestParam String vote) {
    poll1DAO.tallyVote(vote);
    ModelAndView modelAndView = new ModelAndView("PollPage");
    modelAndView.addObject("PollPage", new Cookie("poll1", "voted"));
    return modelAndView;    
}

这是ghs1986-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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.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:annotation-config />

    <context:component-scan base-package="com" />

    <mvc:annotation-driven />

    <mvc:resources location="WEB-INF/pages/images/" mapping="/images/**" />

    <mvc:view-controller path="/" view-name="home" />

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

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost/ghs86" />
        <property name="username" value="root" />
        <property name="password" value="password" />
    </bean>

    <bean id="commentValidator" class="com.validator.CommentValidator" />

    <bean id="commentDAO" class="com.dao.CommentDAO">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="poll1DAO" class="com.dao.Poll1DAO">
        <property name="dataSource" ref="dataSource" /> 
    </bean>

    <bean id="poll2DAO" class="com.dao.Poll2DAO">
        <property name="dataSource" ref="dataSource" /> 
    </bean>

    <bean id="poll3DAO" class="com.dao.Poll3DAO">
        <property name="dataSource" ref="dataSource" /> 
    </bean>

    <bean id="commentController" class="com.controller.CommentController">
        <property name="commentDAO" ref="commentDAO" />
        <property name="commentValidator" ref="commentValidator" />
    </bean>

    <bean id="pollController" class="com.controller.PollController">
        <property name="poll1DAO" ref="poll1DAO" />
        <property name="poll2DAO" ref="poll2DAO" />
        <property name="poll3DAO" ref="poll3DAO" />
    </bean>

    <bean id="poll1Tag" class="com.tags.Poll1Tag" />

    <bean id="poll2Tag" class="com.tags.Poll2Tag" />

    <bean id="poll3Tag" class="com.tags.Poll3Tag" />
</beans>

1 个答案:

答案 0 :(得分:0)

问题解决了。我更改了方法以返回String并返回以下内容:

return "redirect:/polls";