I have put the following submit button in jsp: <TR> <TD ALIGN=CENTER><INPUT TYPE="SUBMIT" NAME="next" VALUE="Next"></TD> </TR>
I have then put the following java code in: <% boolean next = (request.getParameter("next") != null); session.setAttribute("next", next); boolean previous = (request.getParameter("previous") != null); session.setAttribute("previous", previous); int row = 1; session.setAttribute("row", row); %>
now I expected when user hit next button and jsp was forwarded to another jsp that when I did the following:
//get session attributes for next/previous action from previous jsp boolean next = (Boolean) session.getAttribute("next"); boolean previous = (Boolean) session.getAttribute("previous"); int row = (Integer) session.getAttribute("row");
that the boolean next would be set to true, but it is set to false and I do not understand why? Can somebody help please?
I'm thinking that when you go after the 'next' value from the session, that it's not actually set, and, since the default value for the primitive type boolean is false, you're reading that value as false (even thouse it's null in the session. You're code is declaring the next variable as a primitive boolean:
Then, in the jsp look for this:
Or something like that. When you get a chance, check out jstl and the EL. It'll clean up your jsp code considerably. For example, in my jsp code above, it could look like this:
Anyway, you get the idea. [ April 14, 2006: Message edited by: M Anderson ]
Mike -- SCJP, SCWCD
Joined: Mar 26, 2006
Also, is it required that you use buttons? You could use links instead, like this:
Of course, pagehandler.jsp could be any 'handler' like a servlet or whatever you want.
There's another tag out there called the dipsplay tag.
Take a look at http://displaytag.sf.net. It can display your data, as long as it's in a collection of objects that adhere to the JavaBeans rules and provide paging, etc. Otherwise, you'll need to write your own paging code, which can be a challenge in and of itself. You'll probably want to only allow a next link if there are more pages, or a previous if they're pages before these. Also, you'll probably want to display a message like, "viewing page 1 of 10" or whatever... or "viewing items 1 - 10 of 50". The Display tag can handle all of this for you, plus offer the user the ability to sort by columns and some other features.
on the same page as the form with the "next" parameter, you've put the cart before the horse.
This Java will execute on the server in order to format the HTML page containing the form that will be sent to the user. In other words, it will execute long before the user has any chance to click any buttons.