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!!!

Thanks,
I808237

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);
     
     try{
   
          LoginContext lcontext = new LoginContext("WebLogin",webcallback );
         
          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.ServletException: Invalid property in &lt;set&gt;:  ""
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
      org.apache.jsp.authenLogin_jsp._jspService(authenLogin_jsp.java:101)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
root cause
javax.servlet.jsp.JspTagException: Invalid property in &lt;set&gt;:  ""
      org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(Unknown Source)
      org.apache.jsp.authenLogin_jsp._jspx_meth_c_set_0(authenLogin_jsp.java:120)
      org.apache.jsp.authenLogin_jsp._jspService(authenLogin_jsp.java:83)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)

i808237Asked:
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.

AsoraCommented:
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.