This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying data in servlets

 
John Paterson
Ranch Hand
Posts: 171
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys....


I am displaying data recieved from a jsp page 'A' in jsp page 'B'. My code to to do the display is as follow:



My question is, how do I implemet something similar in a servlet? This is what I did:



obvously this allows for the value to be displayed, but only one value. It dosen't help to display multiple values like the earlier jsp example. How do I achieve something like that in a servlet? Hope someone can advise. Thanks.

regards
John
 
Pankaj Kr. Singh
Ranch Hand
Posts: 32
Hibernate Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
You can do as follows

String [] param=request.getParameterValues("music");

out.println("<p>We'll use email to notify you whenever we have new releases for these types of music:</p>\n" );
for(String music:param)
{
out.println("<p>"+music+"</p>");
}
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. These techniques are SO outmoded - you should not use them in new code
2. Look through some of the recent threads in the JSP forum and see what Bear has to say about using scriptlets in JSPs. Poor, patient Bear has to remind people about this thing a few times a day, I'm afraid.
3. Why would you want to fall back on servlets to produce markup? That's stepping even further back into obsolescence than you were when you were using scriptlets in your JSPs.
4. Remember (or know that) a JSP is essentially a servlet. JSPs are meant to be used to further separate the responsibilities of the Controller and the View
5. See the JSP forum and look for what Bear says about things like this. (Yes, I'm aware this is a repeat of #2 but it's something worth mentioning again -- so do it!)
 
John Paterson
Ranch Hand
Posts: 171
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pankaj Singh Hari Om,


Thanks for the reply, I will try it out.


Hi Junilu Lacar ,

I am basically new to Servlets and JSPs. I am trying out exercises from a book. Yes I understand there are better ways of doing it, but since I am new I would just like to try it out as an exercise.

Thanks guys.

regards
John
 
Baseet Ahmed
Ranch Hand
Posts: 225
Java Notepad Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John wrote in servlet:
"

We'll use email to notify you whenever we have new releases for these types of music:

\n"
+ "

" + selectedMusic[0] + "
\n"

obvously this allows for the value to be displayed, but only one value.



This is because you have used index 0 of your array, so always you will get one value. Missed the Looping.


-------
Regards
Ahmed
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic