0

springmvcアプリケーションを実行すると、以下のエラーが発生します。私のコントローラーファイルでは、アノテーションを使用してviewAll.viewをdisplagy Inventory / ListAll.jspにマップしましたが、これは機能していないようです。コントローラファイルのsysoutを使用すると、コンソールに「InViewDVDController.viewAll()」というメッセージが表示されます。

いくつかのマッピングが欠落しているかどうかアドバイスできますか?

Error:

HTTP Status 404 - /SpringMVC/views/inventory/viewAll.jsp

--------------------------------------------------------------------------------

type Status report

message /SpringMVC/views/inventory/viewAll.jsp

description The requested resource (/SpringMVC/views/inventory/viewAll.jsp) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.29

index.html

  <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Highview DVD Management</title>
    </head>
    <body>
     <p> This DVD Management Model contains the following modules</p>

     <ul>
      <li><a href="inventory/viewAll.view">View All DVDs</a> </li>
      <li><a href="inventory/addDVD.form">Add a DVD</a> </li>
     </ul>
    </body>
  </html>

ViewDVDController.java

    @Controller
    public class ViewDVDController extends MultiActionController {
        public ViewDVDController(){
            System.out.println("In ViewDVDController()");
        }
        @Autowired
        private InventoryManager manager;

        public InventoryManager getManager(){
            return manager;
        }

        public void setManager(InventoryManager manager){
            this.manager=manager;
        }

        @RequestMapping(value="viewAll.view", method=RequestMethod.GET)
        public ModelAndView viewAll() throws Exception {
            System.out.println("In ViewDVDController.viewAll()");
            Collection<DVDInfo> all = manager.getAll();
            return new ModelAndView("ListAll","catalog",all);

        }


    }

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_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>Spring MVCDemo</display-name>

    <servlet>
      <servlet-name>spring</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
      <servlet-name>spring</servlet-name>
      <url-pattern>/inventory/*</url-pattern>
    </servlet-mapping>


    <welcome-file-list>
      <welcome-file>index.html</welcome-file>
    </welcome-file-list>

   </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:cotext="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">

   <mvc:annotation-driven/>
   <cotext:component-scan base-package="springmvc"/>     

   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/views/inventory/"/>
    <property name="suffix" value=".jsp" />
   </bean>

   </beans>

log4jログ:

    22:31:38,370 DEBUG ctory.support.DefaultListableBeanFactory: 430 - Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
    22:31:38,372 DEBUG ctory.support.DefaultListableBeanFactory: 458 - Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
    22:31:38,372 DEBUG gframework.web.servlet.DispatcherServlet: 647 - Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@1a0b94d]
    22:31:38,372 DEBUG ctory.support.DefaultListableBeanFactory: 245 - Returning cached instance of singleton bean 'viewResolver'
    22:31:38,373 DEBUG ctory.support.DefaultListableBeanFactory: 430 - Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
    22:31:38,376 DEBUG ctory.support.DefaultListableBeanFactory: 458 - Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
    22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 709 - Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@16c14c0]
    22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 523 - Published WebApplicationContext of servlet 'spring' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.spring]
    22:31:38,377  INFO gframework.web.servlet.DispatcherServlet: 463 - FrameworkServlet 'spring': initialization completed in 804 ms
    22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 136 - Servlet 'spring' configured successfully
    22:31:38,383 DEBUG gframework.web.servlet.DispatcherServlet: 819 - DispatcherServlet with name 'spring' processing GET request for [/SpringMVC/inventory/viewAll.view]
    22:31:38,385 DEBUG .annotation.RequestMappingHandlerMapping: 213 - Looking up handler method for path /viewAll.view
    22:31:38,387 DEBUG .annotation.RequestMappingHandlerMapping: 220 - Returning handler method [public org.springframework.web.portlet.ModelAndView springmvc.presentation.ViewDVDController.viewAll() throws java.lang.Exception]
    22:31:38,388 DEBUG ctory.support.DefaultListableBeanFactory: 245 - Returning cached instance of singleton bean 'viewDVDController'
    22:31:38,390 DEBUG gframework.web.servlet.DispatcherServlet: 902 - Last-Modified value for [/SpringMVC/inventory/viewAll.view] is: -1
    In ViewDVDController.viewAll()
    siz of the collection is  2
    22:31:38,413 DEBUG ctory.support.DefaultListableBeanFactory:1498 - Invoking afterPropertiesSet() on bean with name 'viewAll'
    22:31:38,413 DEBUG gframework.web.servlet.DispatcherServlet:1178 - Rendering view [org.springframework.web.servlet.view.JstlView: name 'viewAll'; URL [/views/inventory/viewAll.jsp]] in DispatcherServlet with name 'spring'
    22:31:38,413 DEBUG pringframework.web.servlet.view.JstlView: 371 - Added model object 'modelAndView' of type [org.springframework.web.portlet.ModelAndView] to request in view with name 'viewAll'
    22:31:38,413 DEBUG pringframework.web.servlet.view.JstlView: 371 - Added model object 'org.springframework.validation.BindingResult.modelAndView' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'viewAll'
    22:31:38,417 DEBUG pringframework.web.servlet.view.JstlView: 236 - Forwarding to resource [/views/inventory/viewAll.jsp] in InternalResourceView 'viewAll'
    22:31:38,420 DEBUG gframework.web.servlet.DispatcherServlet: 913 - Successfully completed request
4

2 に答える 2

1

最後に、私は答えを得ました。org.springframework.web.*サーブレットではなく、間違った ModelAndView クラス (org.springframework.web* .portlet. *ModelAndView)をインポートしていました。*コントローラ ファイルの ModelAndView。

于 2012-12-03T23:12:24.013 に答える
0

ViewDVDController はどのパッケージに入っていますか? base-packageの値(cotext:component-scan 内) はパッケージ名と一致する必要があることに注意してください。

于 2012-12-02T21:46:59.043 に答える