2016-11-15 8 views
-2

私は、Springセキュリティを使用して、ログイン機能を持つ簡単なアプリケーションを作成しようとしています。しかし、私は希望の結果を達成することはできません。 my .jspページのJSTLタグはテストに合格しませんが、スクリプレットコードはアプリケーションで回避したいコードです。JSTL if-checkが機能しないのはなぜですか?

My JSPページ。

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 
<%@ page contentType="text/html;charset=UTF-8" language="java" %> 

<html> 
<head> 
    <title>Log in page</title> 
</head> 
<body> 
<form action="<c:url value="/login"/>" method="POST"> 
    <p> 
     <label for="username">Username</label> 
     <input type="text" id="username" name="username"/> 
    </p> 
    <p> 
     <label for="password">Password</label> 
     <input type="password" id="password" name="password"/> 
    </p> 
    <button type="submit" class="btn">Log in</button> 
</form> 

// This block of code is never executed 
<c:if test="${error != null}"> 
    Some test message 
</c:if> 

// While this one works fine 
<% 
    if (request.getParameter("error") != null) { 
     out.write("error's value isn't null\n"); 
    } 
%> 
</body> 
</html> 

WebSecurityConfigurerAdapterオーバーライドの設定方法:マッピングの

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.csrf().disable(); 

     http.antMatchers("/product") 
      .access("hasRole('ROLE_MANAGER')"); 

     http.authorizeRequests().and().formLogin() 
      .loginPage("/login") 
      .defaultSuccessUrl("/admin") 
      .failureUrl("/login?error") 
      .usernameParameter("username") 
      .passwordParameter("password") 
      .and().logout().logoutSuccessUrl("/login?logout"); 
} 

Spring MVCのコントローラのメソッド "/ログイン" 要求。

@RequestMapping(value = "/login", method = RequestMethod.GET) 
    public String loginPage(Model model, 
          @RequestParam(value = "error", required = false) String error { 
     if (error != null) { 
      model.addAttribute("error", "Username or password is incorrect."); 
     } 

     return "login"; 
    } 

そして、これは私がhttp://localhost/login?errorを要求し得るものです:

Image

答えて

0

私は国連として

<%@ page contentType="text/html;charset=UTF-8" language="java"%> 

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> 

を変更しましたEL評価は無効になったので、私は手動でそれを起動しました。

関連する問題