0

Hi every body, I tried to search for my own problem, I would think this must be popular issue but unfortunately I found no solution in Google.

I tried to use (boolean) session.getAttribute("IsValidUser") to get the attribute of Session, but that caused error:

org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

PWC6197: An error occurred at line: 8 in the jsp file: /WEB-INF/jsp/index.jsp
PWC6199: Generated servlet error:
inconvertible types
  required: boolean
  found:    java.lang.Object

So below is my JSP code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page session="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%! boolean IsValidUser = false ; %>
<%   int LoginTriesTime = 0 ;%>
<%   String UserName = "" ;%>
<%
    try
    {
        IsValidUser = (boolean) session.getAttribute("IsValidUser") ; //THIS IS WHERE THE ERROR CAUSED
    }
    catch (IllegalStateException Ex)
    {
        Ex.printStackTrace();
    }

    if (IsValidUser == true)
    {
        UserName = (String) session.getAttribute("UserName");
    }
    else
    {
        LoginTriesTime = (int) session.getAttribute("LoginTryTimes"); //THIS IS WHERE THE ERROR CAUSED
    }
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome to Spring Web MVC project</title>
    </head>

    <body>
<%
    if (IsValidUser == true)
    {
%>
        <h3>Welcome <%= UserName %></h3>
<%
    }
    else
    {
        response.sendRedirect("login.jsp");
    }
%>

    </body>
</html>

Really appreciate if you guys can help me figure out this. I'm new to JSP

Many Thanks,
Tu Dinh

2
Contributors
2
Replies
10
Views
3 Years
Discussion Span
Last Post by Tu Dinh
0

WOW that looks so simple and makes sense, an Object instead of primitive type.
I will try tonight.

@masijade Thank you so much!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.