Servlet being called multiple times from JSP...

G

GfxGuy

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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top