URL映射问题-Spring Web MVC [英] URL Mapping issue - Spring web MVC

查看:116
本文介绍了URL映射问题-Spring Web MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring和Web MVC模块的新手.基本上,我有以下内容:

I'm a newbie with Spring and web MVC module. Basically, i have the following :

web.xml

<servlet>
    <servlet-name>abc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>abc-dispatcher</servlet-name>
    <url-pattern>/user/*</url-pattern>
</servlet-mapping>

abc-dispatcher-servlet.xml

abc-dispatcher-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"
   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">


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


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

我有一个控制器,相关部分是:

And i have a controller, related parts are :

@Controller
public class ABCController {

@RequestMapping("/user/welcome")
public String printWelcome(ModelMap model) {

    //code

}

现在,只要我尝试访问http://localhost:8080/myapp/user/welcome

Now whenever i try to access http://localhost:8080/myapp/user/welcome

它给我404.

日志说已将url'/user/welcome'映射到处理程序'ABCController',但未能在名称为'abc-dispatcher'的DispatcherServlet中映射URI [/ MYAPP /user/welcome]

Logs say that "mapped url '/user/welcome' onto handler 'ABCController' but it failed to map URI [/MYAPP/user/welcome] in DispatcherServlet with name 'abc-dispatcher' .

完全困惑.我已经检查了所有我们两次指定映射的线程,但是这里不是这种情况.我一定很想念东西!

Totally confused. I have checked all the threads where we specify a mapping twice, but that's not the case here. I must be missing something!

感谢您的帮助!

推荐答案

URL应该为http://localhost:8080/myapp/user/user/welcome.的确,除非将处理程序的alwaysUseFullPath属性设置为true,否则servlet映射将附加到请求映射URL之前,以形成完整路径.

The URL should be http://localhost:8080/myapp/user/user/welcome. Indeed, unless the alwaysUseFullPath property of the handler is set to true, the servlet-mapping is prepended to the request mapping URL to form the full path.

请参见 http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-handlermapping 了解详情:

alwaysUseFullPath

alwaysUseFullPath

如果为true,Spring将使用当前Servlet上下文中的完整路径来查找适当的处理程序.如果为假(默认值),则 使用当前Servlet映射内的路径.例如,如果 Servlet使用/testing/*和alwaysUseFullPath属性进行映射 设置为true,则使用/testing/viewPage.html,而如果 属性设置为false,使用/viewPage.html.

If true , Spring uses the full path within the current Servlet context to find an appropriate handler. If false (the default), the path within the current Servlet mapping is used. For example, if a Servlet is mapped using /testing/* and the alwaysUseFullPath property is set to true, /testing/viewPage.html is used, whereas if the property is set to false, /viewPage.html is used.

这篇关于URL映射问题-Spring Web MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆