我正在将旧的servlet应用程序转换为Spring 3.1.在此过程中,一些URL现在已过时.我们的网络存在一些问题,不会很快得到解决.我的老板不想相信他们的重定向将始终可用.所以,她让我把自己的重定向放到webapp中.
一切都很好,除了如果URL有一个尾部斜杠,Spring 3.1将找不到处理它的Controller类函数.
http://blah.blah.blah/acme/makedonation 被发现,映射和处理
http://blah.blah.blah/acme/makedonation /没有
这是我用来处理遗留URL的控制器类
import org.springframework.stereotype.Controller;
import org.springframework.validation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.apache.log4j.Logger;
@Controller
public class LegacyServletController {
private static final Logger logger = Logger.getLogger(LegacyServletController.class);
// Redirect these legacy screns "home", the login screen via the logout process
@RequestMapping({"makeadonation","contact","complain"})
public String home() {
logger.debug("started...");
return "redirect:logout";
}// end home()
}// end class LegacyServletController
Run Code Online (Sandbox Code Playgroud)
我用Google搜索并找到了这个Stack Overflow 帖子,它提供了一些建议,但我是Spring的新手,并且对它的实现其中的一些建议还不够了解.这个听起来特别适合我的需求:
spring 3.1 RequestMappingHandlerMapping允许您设置"useTrailingSlashMatch"属性.默认情况下,这是真的.我认为将其切换为false会解决您的问题,
有人会给我一个如何做到这一点的基本例子,引用一个有这样一个例子的URL(我没跟谷歌好运)或者指点一个更好的主意吗?
非常感谢史蒂夫
你应该在context.xml中配置你的bean,并设置property.或者您可以参考链接或弹簧文档部分16.4
示例配置
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="useTrailingSlashMatch" value="true">
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5895 次 |
| 最近记录: |