我在Glassfish服务器日志中使用Netbeans ...我看到了
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/app-config.xml]
INFO: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@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.springframework.beans.factory.support.DefaultListableBeanFactory@b91162
INFO: Mapped URL path [/content/edit] onto handler [com.cmt.controllers.Content@1f3e27b]
INFO: Mapped URL path [/content/edit.*] onto handler [com.cmt.controllers.Content@1f3e27b]
INFO: Mapped URL path [/content/edit/] onto handler [com.cmt.controllers.Content@1f3e27b]
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.
表示/content/edit
正在映射到我的控制器,如下所示:
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;
}
}
当我转到该页面时,我继续看到404错误。它显示它已经注册了映射,为什么这不起作用?
我的 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>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我使用了网址http://localhost:8080/content/edit
和http://localhost:8080/CMT/content/edit
答案 0 :(得分:1)
您的网址与您需要html扩展的网址格式不符。所以我怀疑这是问题
<servlet-mapping>
<servlet-name>Spring-MVC-Dispatcher-Servlet</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>