File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Displaying data in servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Displaying data in servlets" Watch "Displaying data in servlets" New topic
Author

Displaying data in servlets

John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 132
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

Joined: Mar 31, 2011
Posts: 32

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

Joined: Feb 26, 2001
Posts: 5018
    
    8

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!)


Junilu - [How to Ask Questions] [How to Answer Questions]
John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 132
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

Joined: Dec 18, 2006
Posts: 224

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying data in servlets