Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSTL: Using c:if to test boolean after a login

843840Feb 7 2009 — edited Feb 7 2009
I'm having a little difficulty getting the c:if tag working.

The error that im getting is javax.servlet.jsp.el.ELException: Unable to find a value for "SuperRole" in object of class "focus.entitiy.bean.User" using operator "."

To explain what I'm doing, a regular jsp posts the username and password to my loginservlet which uses the following code:

HttpSession session = request.getSession();
        DBManager dbmgnr = new DBManager();
        User usr = new User();
        usr.setUsername(request.getParameter("username"));
        usr = dbmgnr.loginQuery(usr, request.getParameter("password"));
        if(usr.getUserId() != 0){
        session.setAttribute("user", usr);
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/menu.jsp");
        dispatcher.forward(request, response);
        
         }else{
            request.setAttribute("loginMessage", "failed");
            RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
            dispatcher.forward(request, response);
            }
        } 
That uses the method loginQuery which is below:

public User loginQuery(User usr, String password) {
        sqlStmt = "SELECT * FROM USERS WHERE username='"+usr.getUsername()+"'";
        ResultSet rs = connectDBExecuteQuery();
        // Populate the user serttings
        try {
            if (rs != null && rs.next()) {
                // does password match?
                if ((rs.getString("password").equals(password))) {
                    usr.setUserId(rs.getInt("user_id"));
                    usr.setPassword(rs.getString("password"));
                    usr.setSuperRole(rs.getBoolean("role_adviceinfo"));
                    //usr.setMngrRole(rs.getBoolean("role_mngr"));
                    //usr.setPlebRole(rs.getBoolean("role_pleb"));
                    }else{
                    usr.setUserId(0);
                    }
                }
        } catch (SQLException sqle) {
            sqle.getMessage();
            sqle.printStackTrace();
        }
        return usr;
    }
As you can see once the login is valid it dispatches the request to menu.jsp which has the following code:
 <%@page contentType="text/html" pageEncoding="UTF-8"%>
<% if(session.isNew()){ response.sendRedirect("/Test/authError.jsp");} %>
<jsp:useBean id="user" class="focus.entitiy.bean.User" scope="session"/>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Menu</title>
</head>
<body>
<h1></h1>
<c:if test="${user.getSuperRole}" >
<p>you are in the superrole</p>
</c:if>
</body>
</html>
and just incase the getter and setter from userbean

 public boolean getSuperRole() {
        return superRole;
    }
    public void setSuperRole(boolean superRole) {
        this.superRole = superRole;
    }
I would be extremely grateful for any help anyone could give me
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2009
Added on Feb 7 2009
3 comments
1,832 views