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.jspservletcookbook.LoginBean" />
(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.request}" 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.ServletException: Invalid property in &lt;set&gt;: (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!!!


The full LoginBean class follows:

package com.jspservletcookbook;          
import javax.servlet.ServletRequest;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

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);
          LoginContext lcontext = new LoginContext("WebLogin",webcallback );
          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;
     public ServletRequest getReq() {              
             return this.req;

Full server error follows:

javax.servlet.ServletException: Invalid property in &lt;set&gt;:  ""
root cause
javax.servlet.jsp.JspTagException: Invalid property in &lt;set&gt;:  ""
      org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(Unknown Source)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This line is invalid

<c:set target="${jaasBean}" value="${pageContext.request}" property="${req}"/>

because ${req} evaluate to nothing

You can fix it to

<c:set target="${jaasBean}" value="${pageContext.request}" property="req"/>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
i808237Author Commented:
That solved the issue!  Thanks expert!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.