English 中文(简体)
SpringMVC: 派遣国 办公室提出其他意见
原标题:SpringMVC: DispatcherServlet makes extra requests to view

I m having a strange problem with Spring MVC. I have a simple controller like this:

@Controller
@RequestMapping("admin")
public class AdminController {

@RequestMapping(value = "", method = RequestMethod.GET)
public String home() {
    return "home";
}

当我管理我的服务器和接驳机时:地方厅/行政部有404个错误。 这一观点已经存在,应当提供。 当我检查我的春季事件记录时,情况是:

DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name  appServlet  processing GET request for [/admin]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /admin
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public java.lang.String be.roots.buildinginspector.web.controller.AdminController.home()]
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean  adminController 
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/admin] is: -1
DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name  home ; URL [home]] in DispatcherServlet with name  appServlet 
DEBUG: org.springframework.web.servlet.view.JstlView - Added model object  domainOfExpertise  of type [be.roots.buildinginspector.business.model.DomainOfExpertise] to request in view with name  home 
DEBUG: org.springframework.web.servlet.view.JstlView - Added model object  org.springframework.validation.BindingResult.domainOfExpertise  of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name  home 
DEBUG: org.springframework.web.servlet.view.JstlView - Forwarding to resource [home] in InternalResourceView  home 
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name  appServlet  processing GET request for [/home]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /home
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/home]
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/home] in DispatcherServlet with name  appServlet 

一切都得到正确处理,但并非只是表明观点,而是发送者Servlet向要求查阅的词库提出新的GET申请。

我的网站:

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”>

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:/spring/config-core-business.xml
                 classpath*:/spring/config-app-security.xml
    </param-value>
</context-param>

<!-- Spring Security filter -->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:/spring/appServlet/config-core-web.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

相关春季背景部分(汇合-核心网站:xml):

<resources mapping="/resources/**" location="../../../resources" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources
     in the /WEB-INF/views directory -->
<beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/"/>
    <beans:property name="suffix" value=".jsp"/>
</beans:bean>
最佳回答

这一切之后,这是一个与散射有关的问题。 由于某种原因,我重新调整了我民主选举学会的组合,这一错误得到了解决。 感谢您的帮助。

问题回答
@Controller
@RequestMapping("admin")
public class AdminController {

@RequestMapping(method = RequestMethod.GET)
public String home() {
    return "home";
}

remove value property of @RequestMapping for home() function.

I think this is servlet mapping problem in web.xml. Change it in web.xml to /admin addreses only. Perhaps now you have:

<url-pattern>*</url-pattern>

change it to:

<url-pattern>/admin/*</url-pattern>

要求绘制你方法的说明,限制了你的控制者回应从“行政/家庭”开始的要求。

I would apply the following modifications :

@Controller
@RequestMapping("/admin")
public class AdminController {

   @RequestMapping(method = RequestMethod.GET)
   public String home() {
      return "home";
   }
}

引证:

@RequestMapping(value = "admin",
        method = {RequestMethod.GET, RequestMethod.POST })




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签