1
저는 스프링 프레임 워크를 사용하여 매우 새롭습니다.스프링 MVC - 요청 매핑
스프링 보안을 사용하여 간단한 로그인을 설정하는 방법을 보여준 자습서를 발견했습니다. 그들은 다음과 같이 HomeController.java
:
home.jsp :
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<link rel="stylesheet" href="../css/styles.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<a href=<c:url value="/j_spring_security_logout"/>>Logout</a><br/>
<sec:authorize ifAnyGranted="ROLE_ADMIN">
<h1>Only admin can see this</h1><br/>
<a href="admin"> Admin Home </a>
</sec:authorize>
<h1>Welcome!</h1>
Logged in as: <c:out value= **"${CurrentUser}"** /> !<br />
</body>
</html>
및 HomeController.java
home.jsp 및 컨트롤러 : 또한 일부 뷰의 코드를 포함package rd.controller;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomeController {
@RequestMapping(value = "/home" , method = RequestMethod.GET)
public String setUp(Model model){
**model.addAttribute("CurrentUser", SecurityContextHolder.getContext().getAuthentication().getName());**
return "home";
}
}
수집 한 내용에서 **로 둘러싸인 줄은 jsp 페이지에 표시 할 속성을 사용할 수 있도록 연결됩니다.
Logged in as: ${CurrentUser}!
나는 논리 검사뿐만 아니라 봄이 컨트롤러와 뷰를 연결해야한다 방법에 대한 설명을 사용할 수 그러나 내가 그 일을하고있어 웹 사이트가 그대로 인쇄하는 방법에 문제가있다. 또한 좋은 봄 튜토리얼 링크도 환영합니다. 감사합니다!
이 유 스프링 설정 파일의 ViewResolver를 구성
}? –
익숙하지 않은 것 같아서 그렇지 않을 수도 있습니다. 어떤 설정 파일을 참조하고 있습니까? pom.xml? 또는 security/login xml 파일 중 하나입니까? – Christy
또한 사용중인 Servlet 버전을 다시 확인하십시오. 버전 2.4 이상을 시도하십시오 –