0

I would like to create a simple car Reservation web-based application that similar to this page. In that page, you can choose your location, destination and also Date of reservation. After you click next, the page will redirect you to another page where you choose time you desire, like this. If you click any of the time button, it will then display you an object ( a car ) that show booked or available seat information in the same page.

I have a database containing Unique ID, Location, Destination, Date, Time, and Seat available. In order to show time like the example above, I have to determine the location, destination, and date first ( since different destination and date will have different time). And to get information about how many seat available left, I have to determine the location, destination, date, and time.

In my application i have 3 .jsp page let's call it First.jsp (user input location, destination and date here) Second.jsp (information filled by user in first.jsp will pass here, and then passed again to third.jsp ) Third.jsp ( user input time here, the data will be passed to second.jsp. The whole data will be processed there. And the data will finally be passed back to Third.jsp displaying seat available information to user.

The problem is, I can pass data from first.jsp to third.jsp just fine. But after i retrieve data from third.jsp and pass it back to second.jsp. Data from the first.jsp is already gone. Which make it impossible for me to process the whole data there.

My overall code works like this :

First.jsp

<form action= second.jsp method= post>

<SELECT class: drop id: location name: locationlist>
   <option value = locationvalue/>
</SELECT>

<SELECT class: drop id: destination name: destinationlist>
   <option value = destinationvalue/>
</SELECT>

<SELECT class: drop id: date name: datelist>
   <option value = datevalue/>
</SELECT>

<input type= submit name=submitbtn/>
</form>

Second.jsp

<c:if test=(param.time is empty)>
   <c:redirect url: third.jsp>
       <c:param name= locationvalue value${param.locationlist>
   </c:redirect>
<c:if/>

<c:if test=(param is not empty>
   <s:query 
      SELECT id, seat FROM schedule WHERE location = 'locationlist' destination = 'destinationlist' date = 'datelist' time = 'timelist' // does not work here 
   </s:query>

Third.jsp

<s:query dataSource="${ds}" var="resultset">
        SELECT DISTINCT time FROM schedule WHERE location = '${param.locationvalue}'
</s:query>

<form action="second.jsp" method="post">
    <center>
        <c:forEach items="${resultset.rows}" var="row">
            <input type="submit" value="${row.time}" name="time">
        </c:forEach>
    </center>
</form>
  • Possible duplicate of [How to pass data between JSP Pages using JSTL?](https://stackoverflow.com/questions/51742401/how-to-pass-data-between-jsp-pages-using-jstl) – Jasper de Vries Aug 09 '18 at 07:49
  • Instead of asking the same question again, try to improve the original question. – Jasper de Vries Aug 09 '18 at 07:50
  • I thought it was somewhat different since in my previous question, i wanted to know how to pass the data. In this question i wanted to know how to keep the data that has been passed. Although it could be just my logic – Kevin Guswanto Aug 09 '18 at 08:10
  • Off topic: you should really read https://stackoverflow.com/questions/601300/what-is-sql-injection – Jasper de Vries Aug 09 '18 at 08:49
  • I don't really get it, but it's true that it happens to my code. When i tried to access the *location* from database, it gives me *destination* instead. I will look for it more, thanks for the reminder ! – Kevin Guswanto Aug 09 '18 at 09:00

1 Answers1

-1

In general practice, <input type="hidden"> will be used for this type of application (Multi step wizard).

So for the sake of simplicity, you can "forward" your input from third.jsp to second.jsp like so:

<form action="second.jsp">
    <input type="hidden" name="fieldname" value="value from first.jsp"/>
    <!--rest of the field in this form-->
</form>

And of course accessing it from second.jsp will be like:

${param.field}
${fn:escapeXml(param.field)} //escape xml in el way
<c:out value="${param.field}"></c:out> //escape xml by default

Another way is to store every single field into your session object. Attribute in session will be persist as long as it is not invalidate or application doesn't clear/override it.

<c:set scope="request" value="${param.field}" var="field"/>

Depend on your context, session management can be done in different way.

ST. Kee
  • 256
  • 2
  • 8