This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP Page redirection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Page redirection " Watch "JSP Page redirection " New topic

JSP Page redirection

Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
Hi all,

I like to know how to populate the listbox dynamically using jsp..

The scenario is i have two list box in my jsp page form where the selection of value from list 1 should populate the list 2.

How can i do it through servlet,jsp so that i retain the previous values entered in my form and also get the list 2 populated based on the value selection in list1.

My problem is how do i redirect/forward (since i use post method - i can change it to get if required) to the appropriate page (I used javascript onchange event) and how i retain the previous entered in the form when i come back to it.

Any inputs /ideas is greatly welcome.. thanx for the time in advance.

Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
anybody there , who can give some ideas.

I try to forward the request on my script onchange event, but this stops loading the whole page itself..

I am populating the listbox using JSTL for:each.

Any inputs is highly appreciated.

Thanx in advance.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

I have an example app that does this.
It's not done with pure JSP (model1).
It uses MVC, but the concept is the same.
Look for Dynamic Select Lists.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
hi Mr.Ben,

Thanx a lot. I went thru the application and it works great.

I have some more clarification..

The form is a jsp that has other additional fields so this selection comes as 6th field which mean the user has filled out the previous 5 fields in the form.

I use Javascript onchange event that directs to a servlet that chooses the relevant values for 2nd list box and forwards back to the JSP.

Here i try to bring back the previous 5 + 1 value entered and selected by the user.

I have done that, since i used JSTL for substituting values in the JSP i find lot of whitespace substituted in the html anyway is there to avoid it.

I am using Tomcat 5.0. Thanx for the time.

[ July 20, 2006: Message edited by: roshini sridhar ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60804

Originally posted by roshini sridhar:
i find lot of whitespace substituted in the html anyway is there to avoid it.

That's pretty much the nature of JSP. This article goes into details regarding the preserving of whitespace.

Except for very large pages, a little whitespace isn't a big deal, but if you are concerned about network overhead, you could write a servlet filter to remove excess whitesapce or to gzip the output.
[ July 20, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
It is sorta covered in the JavaRanch Style Guide.
subject: JSP Page redirection
Similar Threads
populating Action Form with Arraylists values
Retain a selected value in a drop down.
JSP and Dropdown Box
Problem retaining form field after submission
Struts 1.1 question (Might not be an easy one)