Servlet being called multiple times from JSP...

Discussion in 'Java' started by GfxGuy, May 4, 2005.

  1. GfxGuy

    GfxGuy Guest

    Having a problem with my PTO (paid time off) web application. The flow
    works like this:

    pto_select_days.jsp --> pto_check.jsp --> SubmitPTO (servlet)

    pto_check does the logic, checking to make sure that certain values are
    correct (filled in, anyway), the bean "req" is a PTO request bean that
    is automatically filled in and does the calculations for total days and
    so forth...

    The problem seems to lie somewhere in the JSP, where if all the values
    are OK then the SubmitPTO servlet is called and everything works just
    fine. If there are incorrect values, though, the errors are
    displayed... and somehow the SubmitPTO servlet is called TWICE! Yet
    the page is not further redirected to the output from the servlet... it
    stays on this page where the errors in input are displayed. Here's
    some relevent code... it checks that some days were actually selected,
    that the requesting user is actually a valid user, that a phone number
    where the employee can be reached is given or, for unrequested days, a
    reason is given (we don't have sick days and vacation days, just "paid
    time off" which is used for both, so an unrequested day is usually a
    sick day, for example).

    -----------

    <c:set var="redirect" value="true" scope="page"/>
    <c:set var="message" value="" scope="page" />
    <c:set var="total_days" value="${req.total_days}" scope="page" />

    <c:if test="${total_days == 0}">
    <c:set var="redirect" value="false" />
    <c:set var="message" value="${message}<li>No days were selected."/>
    </c:if>

    <c:if test="${req.rid < 1}">
    <c:set var="redirect" value="false" />
    <c:set var="message" value="${message}<li>Invalid user ID: ${req.id}"
    />
    </c:if>

    <c:if test="${empty param.phones && param.scheduled == 'true'}">
    <c:set var="redirect" value="false" />
    <c:set var="message" value="${message}<li>You must enter a phone
    number." />
    </c:if>

    <c:if test="${param.scheduled == 'false'}">
    <c:if test="${empty param.reason }">
    <c:set var="redirect" value="false" />
    <c:set var="message" value="${message}<li>Unscheduled days require a
    reason." />
    </c:if>
    </c:if>

    <c:choose>
    <c:when test="${redirect}">
    <%-- NOTE: this is the ONLY redirect on the page,
    and yes, I tried renaming my variable something else -- %>
    <c:redirect url="servlet/RequestPTO" />
    </c:when>
    <c:eek:therwise>

    <font size="+1">
    The PTO request could not be processed because:
    <font color="red">
    <ul>
    <c:eek:ut value="${message}" escapeXml="false"/>
    </ul>
    <p>
    </font>
    <p>
    Press
    <input type="button" value="here" onclick="history.go(-1)">
    or the back button on your browser to try again.
    </font>

    </c:eek:therwise>
    </c:choose>

    -------------

    So... there's only one "<redirect>" on the whole page, yet the servlet
    gets called twice even though I see the error messages display.
    Moreover, the output from the Servlet (which is just redirected to
    other jsp) is never displayed... I mean, it's called TWICE!! There is
    some information not being shown here, for sake of brevity, but it's
    just web page stuff and getting parameters and so forth... no logic.

    When I check the log, I can see that the error messages are displayed,
    then it should be the end of it (I think), but then, after displaying
    the reason(s) why it wouldn't submit, the servlet is called twice.

    Right now, because of time, I'm switching my logic to the servlet, but
    I'm not happy about that.

    I'm sure it's something stupid I'm doing...
     
    GfxGuy, May 4, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. djskrill
    Replies:
    9
    Views:
    707
    djskrill
    Oct 1, 2003
  2. Apricot
    Replies:
    4
    Views:
    546
    velthuijsen
    Apr 16, 2004
  3. Radu
    Replies:
    7
    Views:
    720
    charlie_Stell
    Aug 28, 2009
  4. Felix
    Replies:
    1
    Views:
    348
    Felix
    Sep 29, 2006
  5. Replies:
    0
    Views:
    156
Loading...

Share This Page