i808237
asked on
Unable to set ServletRequest property of Java bean using JSTL and JAAS
Hello Expert,
I am trying to learn how to use a "JAAS in a JSP" (from Java Servlet an JSP Cookbook page 349) to implement security for my login page. I followed the 'Java Servlet an JSP Cookbook' by creating a login.html file that performs a POST to authenLogin.jsp (sends entered userName and password). A code snippet from login.html follows:
<form method="POST" action="http://localhost:8084/Database2/authenLogin.jsp">
<td>Enter the user name: </td><td><input type="text " name="userName" size="15"></td>
<td>Enter the password: </td><td><input type="password " name="password" size="15"></td>
The authenLogin.jsp is properly called that contains the following code:
1. Taglib JSTL is brought into scope <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2. Next a bean is created called jaasBean <jsp:useBean id="jaasBean" class="com.jspservletcookb ook.LoginB ean" />
(confirmed in debug that the LoginBean object constructor is executed properly to create the object)
3. The next statement fails for me when an attempt is made to set the beans ServletRequest property (called req) to the current request using c:set. It follows:
<c:set target="${jaasBean}" value="${pageContext.reque st}" property="${req}"/>
I used '<c:out' tag to print the values in the request using pageContext.request (I could see information like the userName and password entered in the login.html) to confirm the the request is not null. It seems like the setter method in LoginBean class 'setReq(ServletRequest request)' should get invoked to set the objects' req attribute. (full class is at the bottom of this page)
4. When I run the program, I get the following server error: javax.servlet.ServletExcep tion: Invalid property in <set>: (full error is at the bottom of this page). I assume that the error relates to the fact that the setter method is not getting invoked properly if at all???
I've tried for 2 days to get this to work without success. Any help would be greatly appreciated!!!
Thanks,
I808237
The full LoginBean class follows:
package com.jspservletcookbook;
import javax.servlet.ServletReque st;
import javax.security.auth.login. LoginConte xt;
import javax.security.auth.login. LoginExcep tion;
public class LoginBean {
public ServletRequest req;//pass ServletRequest to WebCallbackHandler to exract
//username and password
boolean loginSuccess;//boolean to indicate whether name and password have
//have passed the login test.
public LoginBean(){ }
public boolean getLoginSuccess() throws LoginException {
if (req == null)
throw new IllegalStateException(
"The ServletRequest cannot be null in getLogin()");
WebCallbackHandler webcallback = new WebCallbackHandler(req);
try{
LoginContext lcontext = new LoginContext("WebLogin",we bcallback );
lcontext.login();
return true;
} catch (LoginException lge){
return false;
}
} //getLoginSuccess
public void setReq(ServletRequest request) {
if (request == null)
throw new IllegalArgumentException(
"ServletRequest argument was null in: "+getClass().getName());
this.req = request;
}//setReq
public ServletRequest getReq() {
return this.req;
Full server error follows:
javax.servlet.ServletExcep tion: Invalid property in <set>: ""
org.apache.jasper.runtime. PageContex tImpl.doHa ndlePageEx ception(Pa geContextI mpl.java:8 46)
org.apache.jasper.runtime. PageContex tImpl.hand lePageExce ption(Page ContextImp l.java:779 )
org.apache.jsp.authenLogin _jsp._jspS ervice(aut henLogin_j sp.java:10 1)
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:99)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 25)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:295)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:245)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
org.netbeans.modules.web.m onitor.ser ver.Monito rFilter.do Filter(Mon itorFilter .java:362)
root cause
javax.servlet.jsp.JspTagEx ception: Invalid property in <set>: ""
org.apache.taglibs.standar d.tag.comm on.core.Se tSupport.d oEndTag(Un known Source)
org.apache.jsp.authenLogin _jsp._jspx _meth_c_se t_0(authen Login_jsp. java:120)
org.apache.jsp.authenLogin _jsp._jspS ervice(aut henLogin_j sp.java:83 )
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:99)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 25)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:295)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:245)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
org.netbeans.modules.web.m onitor.ser ver.Monito rFilter.do Filter(Mon itorFilter .java:362)
I am trying to learn how to use a "JAAS in a JSP" (from Java Servlet an JSP Cookbook page 349) to implement security for my login page. I followed the 'Java Servlet an JSP Cookbook' by creating a login.html file that performs a POST to authenLogin.jsp (sends entered userName and password). A code snippet from login.html follows:
<form method="POST" action="http://localhost:8084/Database2/authenLogin.jsp">
<td>Enter the user name: </td><td><input type="text " name="userName" size="15"></td>
<td>Enter the password: </td><td><input type="password " name="password" size="15"></td>
The authenLogin.jsp is properly called that contains the following code:
1. Taglib JSTL is brought into scope <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2. Next a bean is created called jaasBean <jsp:useBean id="jaasBean" class="com.jspservletcookb
(confirmed in debug that the LoginBean object constructor is executed properly to create the object)
3. The next statement fails for me when an attempt is made to set the beans ServletRequest property (called req) to the current request using c:set. It follows:
<c:set target="${jaasBean}" value="${pageContext.reque
I used '<c:out' tag to print the values in the request using pageContext.request (I could see information like the userName and password entered in the login.html) to confirm the the request is not null. It seems like the setter method in LoginBean class 'setReq(ServletRequest request)' should get invoked to set the objects' req attribute. (full class is at the bottom of this page)
4. When I run the program, I get the following server error: javax.servlet.ServletExcep
I've tried for 2 days to get this to work without success. Any help would be greatly appreciated!!!
Thanks,
I808237
The full LoginBean class follows:
package com.jspservletcookbook;
import javax.servlet.ServletReque
import javax.security.auth.login.
import javax.security.auth.login.
public class LoginBean {
public ServletRequest req;//pass ServletRequest to WebCallbackHandler to exract
//username and password
boolean loginSuccess;//boolean to indicate whether name and password have
//have passed the login test.
public LoginBean(){ }
public boolean getLoginSuccess() throws LoginException {
if (req == null)
throw new IllegalStateException(
"The ServletRequest cannot be null in getLogin()");
WebCallbackHandler webcallback = new WebCallbackHandler(req);
try{
LoginContext lcontext = new LoginContext("WebLogin",we
lcontext.login();
return true;
} catch (LoginException lge){
return false;
}
} //getLoginSuccess
public void setReq(ServletRequest request) {
if (request == null)
throw new IllegalArgumentException(
"ServletRequest argument was null in: "+getClass().getName());
this.req = request;
}//setReq
public ServletRequest getReq() {
return this.req;
Full server error follows:
javax.servlet.ServletExcep
org.apache.jasper.runtime.
org.apache.jasper.runtime.
org.apache.jsp.authenLogin
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
org.netbeans.modules.web.m
root cause
javax.servlet.jsp.JspTagEx
org.apache.taglibs.standar
org.apache.jsp.authenLogin
org.apache.jsp.authenLogin
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
org.netbeans.modules.web.m
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER