I am almost totally new to Java EE (Spring, JSTL, ...). I am managing to make login page by spring 4 and JSTL but the denied page 403 failed to show due to parsing error. I don't know the reason why it is unable to parse JSTL tag, just remove it and it works properly, of course, it can not get object from model and show value.
Thanh Nhut
Error :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Nov 06 14:23:20 ICT 2016
There was an unexpected error (type=Internal Server Error, status=500).
Exception parsing document: template="403", line 1 - column 18
Controller :
public class LoginController {
@GetMapping("/")
public String index() {
return "Welcome to the home page!";
}
@RequestMapping(value = "/403", method = RequestMethod.GET)
public ModelAndView accesssDenied() {
ModelAndView model = new ModelAndView();
//check if user is login
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (!(auth instanceof AnonymousAuthenticationToken)) {
UserDetails userDetail = (UserDetails) auth.getPrincipal();
System.out.println(userDetail);
model.addObject("username", userDetail.getUsername());
}
model.setViewName("403");
return model;
}
}
templates/403.jsp :
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<h1>HTTP Status 403 - Access is denied</h1>
<c:choose>
<c:when test="${empty username}">
<h2>You do not have permission to access this page!</h2>
</c:when>
<c:otherwise>
<h2>Username : ${username} <br/>You do not have permission to access this page!</h2>
</c:otherwise>
</c:choose>
</body>
</html>