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 How to get an ArrayList Object in servlet from JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get an ArrayList Object in servlet from JSP? " Watch "How to get an ArrayList Object in servlet from JSP? " New topic
Author

How to get an ArrayList Object in servlet from JSP?

Edward Mahimairaj
Greenhorn

Joined: Jun 10, 2005
Posts: 2
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get an ArrayList Object in servlet from JSP?