제3장 Enhancing the User Experience(Login)
2639 단어 login
Implementing the login controller
@Controller
public class LoginLogoutController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = "/login.do")
public void home() {
}
}
Adding the login JSP
there are 2 important elements of the login form that must be correct in order for the appropriate actions to occur:
The form action must match the action configured in the UsernamePasswordAuthenticationFilter servlet filter. By default, this form action is j_spring_security_check.
The form fields for username and password must match the servlet specifications. By default j_username and j_password are the form field names.
All this leaves us with a fairly simple JSP:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<jsp:include page="common/header.jsp">
<jsp:param name="pageTitle" value="Login"/>
</jsp:include>
<h1>Please Log In to Your Account</h1>
<p>
Please use the form below to log in to your account.
</p>
<form action="j_spring_security_check" method="post">
<label for="j_username">Login</label>:
<input id="j_username" name="j_username" size="20" maxlength="50"
type="text"/>
<br />
<label for="j_password">Password</label>:
<input id="j_password" name="j_password" size="20" maxlength="50"
type="password"/>
<br />
<input type="submit" value="Login"/>
</form>
<jsp:include page="common/footer.jsp"/>
Be aware that you must use a form POST, otherwise the login request will be rejected by the UsernamePasswordAuthenticationFilter.
Configuring Spring Security to use our Spring MVC login page
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login.do" access="permitAll"/>
<intercept-url pattern="/*" access="hasRole('ROLE_USER')" />
<form-login login-page="/login.do" />
</http>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【Ruby on Rails】 gem의 devise를 사용하여 이름과 비밀번호만으로 로그인하는 방법Rails 5.2.4.3 잘 모르는 경우의 참고로 해 주시면 좋겠습니다. homes 컨트롤러를 작성해, 이하를 기술 완료. config/routes.rb app/controllers/homes_controller.r...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.