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

sending a Collection from JSP to Servlet

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


Can i send this to a servlet ??


Save India From Corruption - Anna Hazare.
jack wenttohill
Greenhorn

Joined: Apr 26, 2009
Posts: 9


Then in servlet use


And please study the scope of jsp/servlet you will better understand more.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


This is not possible . Is this possible with getParameter()??
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Can i send this to a servlet ??


yes you can , but shouldn't. What you achieve by calling servlet from JSP. ( it should be other way around)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
What do you mean by "send"? A JSP generates HTML which is then sent to the browser. Where does a servlet enter the picture?
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

sorry for the confusion , i thought tha question is clear :


The question is :

JSP is submitting form data :



<form method="post" action="/MySevlet">
<input type=hidden name="name" value="al"/>

</form>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
Now it's clear. You can't use Java objects in HTML forms; you'll need to add all list items individually as hidden form fields.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234



Thank you ulf ,

I just wanted to try but this is not even compiling "


Then how to send a java array to servlet from jsp ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
By doing what I suggested before.

Check the javadocs of HttpServletRequest for the reason why you're getting a compiler error.
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
Yes it will give compilation error.
To be precise a Class Cast Exception.

getParameter() api returns String and you are trying to cast with ArrayList.

Regarding to the question, one cannot pass the Array object as part of input as it will take only Strings
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you ulf and Mohamed for the explanations .

Please tell me


How can i send this Array to a Servlet .
Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

You can comma separate array and send it to servlet using AJAX..


Skanda
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Other than that is there any other way ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sending a Collection from JSP to Servlet