0

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>
Thunder knight
  • 284
  • 3
  • 5
  • Might this help you - http://stackoverflow.com/questions/5148180/how-to-add-jstl-to-maven – Arpit Aggarwal Nov 06 '16 at 09:48
  • @Arpit Thank you for your link, but after adding these dependencies : taglibsstandard1.1.2 javax.servletjstl1.2 Nothing changes. Same error. – Thunder knight Nov 08 '16 at 10:39
  • Can you show the exact error? – Arpit Aggarwal Nov 08 '16 at 12:20
  • @Arpil : exact error is above in my question, I just copy and paste here for quick reference : 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 – Thunder knight Nov 11 '16 at 12:43

0 Answers0