• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to add the values to combo box

 
sravan ku
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

This is my code snippet


sample output : directory 1 ,dir 2,dir3


My query :

Can any one please tell me how to add this output to combo box in jsp page ?


thanks,
ksk

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, there's a lot to talk about here:

Frist of all, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

I've gone ahead and added the code tags for you. See how much easier the code is to read?

Secondly, you should not be using Java code in a JSP. That's a bad practice from 12 years ago! Do you not feel it is time to modernize? Please see this JspFaq entry.

Another point, correct terminology is important so that we all understand what's being talke about: HTM has no "combo box". Please see
HtmlHasNoComboBox.

What would be best is if you obtained the list for files to be displayed as options in the dropdown in the page controller and passed it to the JSP as a scoped variable. The in the JSP, you could use the JSTL and EL to iterate over the list and create option elements.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, if you were to put a List of the file names into request scope with the name fileList, you could use code similar to the following:

 
sravan ku
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply .

Pardon me ,I am new to this forum I didn't read the guidelines :-( any how thanks for the first step.

I want to display each directory in jsp combo box .

Like > If I am having 3 directories like x,y,z . I want all these directories in the combo box .



PREVIOUSLY I was done like this but all the directories are appearing in a single line .
I want each one of that directory in different line .

Thanks,
ksk
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sravan ku wrote:I want to display each directory in jsp combo box .

Again, there is no such thing as a "combo box". Most people use the term dropdown or select element.

Like > If I am having 3 directories like x,y,z . I want all these directories in the combo box .

I already showed you how to do it using JSTL and EL.
 
sravan ku
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bear Bibeault

Okay got it .

I will try and get back to you soon ..

I will keep in mind to use the correct terminology .



Thanks,
ksk
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Almalyn caguioa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use the following code

ArrayList s = new ArrayList();

s.Add("aaa"); s.Add("bbb"); s.Add("ccc"); ...

this.comboBox2.DataSource = s;

(or)

string[] s = {"a","b","c","d","1","2","3","4"};

this.comboBox2.DataSource = s;

(or)

char[] s = {'a','b','c'};

this.comboBox2.DataSource = s;

(or)

this.comboBox2.Items.Add("Select");
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm, none of that code seems at all relevant to the issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic