你想保护网站吗?在这种情况下,您最好将Spring Security连接到项目中并让它为您管理URL安全。
但如果你真的想要映射一些着眼于/然后在你的应用环境下,你还可以添加这样的事情
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!--facilitates mapping of Dispatcher Servlet to /-->
<mvc:default-servlet-handler/>
<mvc:view-controller path="/" view-name="login"/>
</beans>
这将使用参数化视图控制器
转发/请求登录视图
仍然不确定为什么你会这样做,因为即使你想在没有安全框架的情况下进行登录/安全检查,Filter也是更好的选择。
编辑:这里是如何通过控制器本身
@RequestMapping("/")
@Controller
public class MyController {
@RequestMapping()
public String showMeTheLoginPage() {
return "redirect:/login.html";
}
}
如何你'DispatcherServlet'映射'web.xml'做呢? –
@TomaszNurkiewicz \t \t 弹簧的Servlet servlet的名称> \t \t / URL模式> \t servlet的映射> –