你想保護網站嗎?在這種情況下,您最好將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的映射> –