• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

struts question

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
This is vardhan,
I have one problem with struts.
IN jsp iam entering one number and iam taking that number in action class and iam inserting integers from 1 to upto that given number in an ARRAYLIST.After that iam placing that arraylist object in session.NOw I want to get that arraylist object in the seccess jps page and i want to print that arraylist.
but in success.jsp page iam getting class cast exception.
here iam provindin the coed.Can any one give the suggession:
ACTION CLASS execute method:
{
InsertForm insert=(InsertForm)form;
String number=insert.getNumber();
int n=Integer.parseInt(number);
ArrayList al=new ArrayList();
for(int i=0;i<n;i++)
al.add(new Integer(i));
System.out.println(al);
String target="success";
if(number==null)
{ target="failure";

}
else
{ HttpSession session = request.getSession(true);
session.setAttribute("al","al");
}

return (mapping.findForward(target));

}
SUCCESS.JPS:<%@page import="java.util.ArrayList" session="true"%>
<html>
<head><title></title></head>
<body>
<p><b>SUCESS FULL INSERTION IN THE ARRAYLIST</b></P>
</body>
</html>
<%/////here in this line it is giving the error////
ArrayList a=(ArrayList)session.getAttribute("al");
out.println(a);
%>

STRUTS-CONFIG.XML:
<action path="/insert" type="InsertAction" name="InsertForm">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/index.jsp"/>
</action>
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi vardhan

In your Action class

Change this line
session.setAttribute("al","al");
to
session.setAttribute("al",al);

Hope now program runs
 
Vardhan Muthineni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI sagar
thank u yar
thanks alot.
I got it.
Keep in touch,have a nice day
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic