ww.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
?
? ?
? ? ?
? ?
? ? ?
? ? ? ? ? ? class="org.springframework.web.servlet.view.UrlBasedViewResolver">
? ? ? ? ? ? ? ? ? ? value="org.springframework.web.servlet.view.JstlView" />
? ? ? ?
? ? ? ?
? ?
?
6. 新建HelloSpringSecurityController.java文件,代码如下:
package com.favccxx.favsecurity.web;
?
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
?
@Controller
public class HelloSpringSecurityController {
? ? ?
? ? @RequestMapping("/hello")
? ? public ModelAndView hello(){
? ? ? ? ModelAndView mav = new ModelAndView();
? ? ? ? mav.addObject("title", "Welcome - Spring Security Hello World");
? ? ? ? mav.addObject("message", "This is welcome page!");
? ? ? ? mav.setViewName("/hello");
? ? ? ? return mav;
? ? }
? ? ?
? ? @RequestMapping(value = { "/", "/welcome" }, method = RequestMethod.GET)
? ? public ModelAndView welcome() {
? ? ? ? ModelAndView mav = new ModelAndView();
? ? ? ? mav.addObject("title", "Welcome - Spring Security Hello World");
? ? ? ? mav.addObject("message", "This is welcome page!");
? ? ? ? mav.setViewName("/hello");
? ? ? ? return mav;
? ? }
? ? ?
? ? @RequestMapping(value = "/admin", method = RequestMethod.GET)
? ? ? ? ? public ModelAndView admin() {
? ? ? ?
? ? ? ? ? ? ? ModelAndView mav = new ModelAndView();
? ? ? ? ? ? ? mav.addObject("title", "Admin - Spring Security Hello World");
? ? ? ? ? ? ? mav.addObject("message", "This is protected page!");
? ? ? ? ? ? ? mav.setViewName("/admin");
? ? ? ? ? ? return mav;
? ? ?
? ? ? ? }
? ? ?
? ? }
?
}
7. 在/WEB-INF/views文件夹下分别创建admin.jsp和hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
? ? pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>? ?
${title}
? ? Title : ${title}
? ? Message : ${message}
? ?
? ? ? ?
? ? ? ? ? ? Welcome : ${pageContext.request.userPrincipal.name} | "> Logout
? ? ? ?
? ? ? ?
<%@ page language="java" contentType="text/html; charset=UTF-8"
? ? pageEncoding="UTF-8"%>
${title}
? ? Title:${title}
? ? Message:${message}
?8. 系统运行效果图如下


