Note that there are some explanatory texts on larger screens.

plurals
  1. POJava and JSTL/EL: How can I compare two integers stored as attributes?
    primarykey
    data
    text
    <p>I'm developing a web-app and I have three static variables in my class called AccountManagement that represent the three possible states that can be reached when clicking on a link in an e-mail to activate an account:</p> <pre><code>public final static int ACTIVATION_EXCEPTION_OCCURRED = -1; public final static int ACTIVATION_CODE_INCORRECT = 0; public final static int ACTIVATION_SUCCESSFUL = 1; </code></pre> <p>On startup, these are stored in the context as attributes named "activationSuccessful", "activationCodeIncorrect", and "activationExceptionOccurred". When a user clicks on the link in the e-mail in order to activate the account, the request is sent to the AccountManagementServlet, and his/her first name and the result of the activation code check are added as attributes to their session (which is created if they don't have one yet). The attribute names are "firstName" and "activationStatus" (respectively). The servlet then redirects to activation_status.jsp.</p> <p>The problem i'm having is that, for some reason, the EL equality statements in that JSP don't evaluate, leaving me with a blank page. </p> <p>I'm thinking it's because I stored them as primitive integers, and they're being retrieved as objects. If so, how can I cast them in to integers for the comparison? And if that isn't the problem, can someone kindly tell me what it may be? If I replace all the servletContext attributes in the code below with their respective integers, EL seems to cast the sessionScope attributes to integers based on the presence of an actual integer and the code works. I don't want to hard-code the numbers in to the jsp, so if someone could help me out here I'd be grateful. Here is the code for the JSP:</p> <pre><code>&lt;c:choose&gt; &lt;c:when test="${sessionScope.activationStatus == servletContext.activationSuccessful}"&gt; Congratulations ${sessionScope.firstName}, you've activated your account! &lt;/c:when&gt; &lt;c:when test="${sessionScope.activationStatus == servletContext.activationCodeIncorrect}"&gt; Hi ${sessionScope.firstName}, this activation code is incorrect, please try clicking the link in the e-mail (or the copy and paste instructions) again. If you still end up here, &lt;a href ="send_another_activation_code_page.html"&gt;you'll need to get another activation code&lt;/a&gt; &lt;/c:when&gt; &lt;c:when test="${sessionScope.activationStatus == setvletContext.activationExceptionOccurred}"&gt; Hi ${sessionScope.firstName}, an error occurred during activation, please try clicking the link in the e-mail (or the copy and paste instructions) again. If you still end up here, most likely the time period to activate this account has expired. Don't fret, but you can sign up again (with the same e-mail, if you wish) &lt;a href="index.html"&gt;here&lt;/a&gt;! &lt;/c:when&gt; &lt;/c:choose&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload