2012-03-13 18 views
1

コントローラをセットアップしようとしていて、残念ながら出力を表示できません...すべてが正しくレンダリングされています。私がhttp://localhost:8080/CMT/content/editに行くと、私は404ページを取得します。 Netbeansのから私のアプリを実行すると、http://localhost:8080/CMT@RequestMappingが正しくマッピングされていません

package com.cmt.controllers; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.servlet.ModelAndView; 

@Controller 
public class Content { 

    @RequestMapping(value="/content/edit", method=RequestMethod.GET) 
    public ModelAndView edit(Model model) { 
     ModelAndView mv = new ModelAndView(); 
     mv.setViewName("index"); 
     return mv; 
    } 
} 

アプリ-config.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"> 
    <!-- Scans the classpath of this application for @Components to deploy as beans --> 
    <context:component-scan base-package="com.cmt" /> 
    <!-- Configures the @Controller programming model --> 
    <mvc:annotation-driven /> 
    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory --> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/jsp/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 
</beans> 

web.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/applicationContext.xml</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/app-config.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

どのように私はこれをデバッグしているかを見ることができますに行きます働いていないものは何ですか?

更新

NetBeansでGlassFishサーバーログを

INFO: Pre-instantiating singletons in org.s[email protected]1531ed: defining beans [content,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,viewResolver]; parent: org.s[email protected]b91162 
INFO: Mapped URL path [/content/edit] onto handler [[email protected]] 
INFO: Mapped URL path [/content/edit.*] onto handler [[email protected]] 
INFO: Mapped URL path [/content/edit/] onto handler [[email protected]] 
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver. 
INFO: FrameworkServlet 'Spring-MVC-Dispatcher-Servlet': initialization completed in 1234 ms 
INFO: WEB0671: Loading application [CMT] at [/CMT] 
INFO: CMT was successfully deployed in 3,725 milliseconds. 
+0

web.xmlのサーブレットが正しく設定されていますか? – alephx

+0

コモンズロギングはあなたに何かを伝えていますか?/WEB-INF/jsp /フォルダにindex.jspという名前のファイルがありますか? web.xmlはどのようなものですか? – smp7d

+0

@ smp7d - web.xmlを追加しました。はい、jspフォルダにindex.jspがあります。 – Webnet

答えて

2

を示してはweb.xml/*にマッピングされappという名前DispatcherServletですか?あなたのprevious質問から私は以下を参照してください。

<servlet> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/app-config.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    <url-pattern>*.htm</url-pattern> 
</servlet-mapping> 

/content/edit URLが*.htmパターンと一致していません。可能な回避策として/content/edit.htmを試してください。

+0

すばらしいキャッチ!!運がない '* .htm'の代わりに'/* 'を使ってみました。私はURLに.htmを必要とせず、単にファイル拡張子を避けたいと思う。 – Webnet

関連する問題