How to pass array of object as request parameter in jsp

2,268 views
Skip to first unread message

sachin yewale

unread,
Sep 22, 2011, 3:15:26 AM9/22/11
to indi...@googlegroups.com

Hi all,

Can any one please tell me ho to pass array of object as request parameter in jsp and retrieve it in another jsp.
For e.g i have
double total[]={1,2,3};

and want to pass as request.setAttribute("total",total);


and retrieve in another jsp page
with
double sac[]=request.getAttribute("total");

{it goves error cannot convert form object to double[]}

Please help me.


Regards,
Sachin Yewale

Icon Web Solutions

unread,
Sep 23, 2011, 2:29:18 AM9/23/11
to indi...@googlegroups.com
Perhaps a cast will remove the error,

double sac[]= (double[]) request.getAttribute("total");

--
You received this message because you are subscribed to the Google Groups "IndiJava - India Java User Group & Java Community." group.
To post to this group, send email to indi...@googlegroups.com
To unsubscribe from this group, send email to indijava-u...@googlegroups.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.indijava.in - India Java User Group & Java Community.
http://groups.google.com/group/indijava/
 
Java Fresher Jobs : http://www.indijava.in/community/fresher-jobs
Quiz : http://www.indijava.in/community/QUIZ
Java News: http://www.indijava.in/community/java-news
Tutorials: http://www.indijava.in/community/tutorials
Forum http://www.indijava.in/community/forum
SCJP Resources : http://www.indijava.in/community/category/certifications/scjp
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



--
-----------------------------------------------------
Dinesh Chanchalani
~USA~ 718-408-4482
~India~ 99696-13412

www.IconWebSolutions.info
www.IconTraining.info
www.JavaIssues.com
www.MumbaiProjector.in 


"The fundamental principle of economic activity is that no man you transact with will lose; then you shall not"
- Chanakya in Arthashastra

“Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don’t quit” - Conrad Hilton

कदम निरंतर बढ़ते जिनके, श्रम जिनका अविराम है,
विजय सुनिश्चित होती उनकी, घोषित यह परिणाम है |

srijani basak

unread,
Sep 23, 2011, 2:49:30 AM9/23/11
to indi...@googlegroups.com
you can set the request attribute,
 
request.setAttribute("name", ArrayObject);
 
in JSp,
 
request.getAttribute("name");

sachin yewale

unread,
Sep 23, 2011, 3:19:21 AM9/23/11
to indi...@googlegroups.com
Thanks for reply
But i tried to do this

double sac[]= (double[]) request.getAttribute("total");

but it gives error classCast exception



Regards,
Sachin Yewale

kurapati ramakrishna

unread,
Sep 23, 2011, 4:31:44 AM9/23/11
to indi...@googlegroups.com
try to do this ,it is put in one for loop
double parm[]= (double[]) request.getAttribute("total"+[i]);

kirankumar shendage

unread,
Sep 23, 2011, 5:54:04 AM9/23/11
to indi...@googlegroups.com, sach...@gmail.com
hiiii,

in one jsp page set the array in request scope
<%

double total[]={1,2,3};
request.setAttribute("total",total);
%>

and access it in another page like this..

double total[]=(double[])request.getAttribute("total");
for(int i=0;i<total.length;i++)
{
out.print("arry :"+total[i]);
}
%>

Swapnil Pawecha

unread,
Sep 23, 2011, 8:04:02 AM9/23/11
to indi...@googlegroups.com
you can pass object through link like(" next.jsp?arrary="+total)

--
You received this message because you are subscribed to the Google Groups "IndiJava - India Java User Group & Java Community." group.
To post to this group, send email to indi...@googlegroups.com
To unsubscribe from this group, send email to indijava-u...@googlegroups.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.indijava.in - India Java User Group & Java Community.
http://groups.google.com/group/indijava/
 
Java Fresher Jobs : http://www.indijava.in/community/fresher-jobs
Quiz : http://www.indijava.in/community/QUIZ
Java News: http://www.indijava.in/community/java-news
Tutorials: http://www.indijava.in/community/tutorials
Forum http://www.indijava.in/community/forum
SCJP Resources : http://www.indijava.in/community/category/certifications/scjp
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



--
Swapnil Pawecha

kurapati ramakrishna

unread,
Sep 27, 2011, 6:08:07 AM9/27/11
to indi...@googlegroups.com
double sac[]=(double[])request.getAttribute("total");

raghav bhat

unread,
Sep 24, 2011, 12:07:37 AM9/24/11
to IndiJava - India Java User Group & Java Community.
seems there is error somewhere else in ur program. this works fine.
check this.

page1.jsp

<html>
<body>
<form method=post action="myserv">

<h1>Hello World!</h1>
<input type=submit value="ok">
</form>
</body>
</html>




myserv.java

public void doPost(HttpServletRequest request,HttpServletResponse
response){

double arr[]={12,22,22};
try{
request.setAttribute("arr",arr);
javax.servlet.RequestDispatcher
rd=request.getRequestDispatcher("page2.jsp");

rd.forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}}}




page2.jsp



<html>
<%double ar[]=(double[])request.getAttribute("arr");%>
<body>
<%out.println(ar[0]);%>
<%out.println(ar[1]);%>
<%out.println(ar[2]);%>
</body>
</html>



















Girish Ponkiya

unread,
Sep 23, 2011, 11:12:20 AM9/23/11
to indi...@googlegroups.com
try using generic class Vector<ObjectType>..
Regards,
Girishkumar M. Ponkiya
M.Tech. (CSE) student
Indian Statistical Institute
Kolkata.

Reply all
Reply to author
Forward
0 new messages