Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get an ArrayList Object in servlet from JSP?

 
Edward Mahimairaj
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

please give the solution for this without using session and application...


In test1.jsp file
i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.

After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")


---------Code----------
<jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />

<jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
<%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
<jsp:setProperty name="payment" property="strDate" param="expirationDate" />
<jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
<%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
<jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
<jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>


<jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
<%
lis.add(payment);
%>

</jsp:useBean>

<%
request.setAttribute("lis1",lis);
%>
-----------Code in JSP-----------------

In testServlet.java

i tried to get the arraylist object in servlet using request.getAttribute

But I unable to get that arrayObject in servlet.....

So if any one help me out in this, it will be very helpfull to me..

Thanks in Advance

Edward
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have any form in your page?
Are you using submit button to submit the request to the servlet?

Please read about request lifecycle.

[edited after googling around]

I tried to get some link on it for a while. But no success. So, just take this statement.

When you request to servlet by submitting a page via html submit button or javascript submit function then it would be a brand new request. The old request object will be vanished.
[ June 10, 2005: Message edited by: Adeel Ansari ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP is generally the last component in the request chain.
As Adeel mentioned, this is not the place to add things to a request object unless you are forwarding back to the servlet again before sending the output to the browser.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic