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 Issue: c:redirect loses session attributes?

843840Jan 10 2010 — edited Jan 10 2010
Hey all,

I'm new to JSP/JSTL, and I have the following problem:

I have a page1.jsp with the following code:
                <c:if test="${not empty param.username}">
                    <%
                        String name = request.getParameter("username");
                        System.out.print(name);
                        session.setAttribute("username", name);
                    %>
                    <c:redirect url="/page2.jsp"/>
                </c:if>
And a page2.jsp with the following code:
<c:if test="${empty sessionContext.username}">
    <c:redirect url="/page1.jsp"/>
</c:if>
What it should do is, page1 directs to page2 if a user has entered a username, otherwise it stays on page1.
Page2 should check for a username in the SessionScope so that people who manually type in CONTEXT/page2.jsp are redirected to page1 to provide a username.
I have, however the problem that all my session attributes get lost after the call of c:redirect in page1.

Is that intended?
If so, is there a fix for it (I know ways to do it eventually, but I wanted to use the JSTL EL a bit, and I don't think one should lose all his session attributes on a redirect, right?)

Edited by: sunami on Jan 10, 2010 5:50 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 7 2010
Added on Jan 10 2010
1 comment
447 views