设为首页 加入收藏

TOP

Spring Security身份认证之HelloSpringSecurity(附源码)(二)
2015-02-02 14:11:34 来源: 作者: 【 】 浏览:66
Tags:Spring Security 身份认证 HelloSpringSecurity 源码
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. 系统运行效果图如下


Spring Security身份认证之HelloSpringSecuritySpring Security身份认证之HelloSpringSecuritySpring Security身份认证之HelloSpringSecurity


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++2015前瞻 下一篇Android JSON解析数据

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: