简体   繁体   English

基于表单的身份验证将变量传递给JSP

[英]Form Based authetication passing variable to JSP

We are using a form based authentication and below is the snippet from web.xml 

 <login-config>
  <auth-method> FORM </auth-method>
  <form-login-config>
        <form-login-page>/login.jsp?fromIndex=true</form-login-page>
        <form-error-page>/login.jsp?fromIndex=true&ldapAuth=fail</form-error-page>
    </form-login-config>
 </login-config>

And i do have a loginfilter that processes the authentication. 而且我确实有一个登录过滤器来处理身份验证。 So if the authentication fails i also want to send a error code to jsp to display error message. 因此,如果身份验证失败,我也想向jsp发送错误代码以显示错误消息。 Since the HttpRequest is not carried over to the JSP page when authentication fails i cannot send the variable by putting in http request . 由于认证失败时HttpRequest不会传递到JSP页面,因此我无法通过放置http request来发送变量。

is there a alternate way to pass a variable to the login-errore jsp page ? 有没有另一种方法可以将变量传递给登录错误的jsp页面?

Instead through a parameter, you should put your data in the HttpRequest through an attribute : 而是通过参数,应通过属性将数据放入HttpRequest

// In the filter:
request.setAttribute("name", new MyObject());

// In the JSP:
MyObject obj=(MyObject)request.getAttribute("name");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM