1

I have a method in a java class that returns an ArrayList of a particular class type. How can it be passed as a request parameter?

1
  • what are you calling a "request parameter" ? some code, even if not working, would be great to understand Commented Mar 8, 2011 at 13:24

2 Answers 2

2

in your servlet

request.setParameter("dataList",methodThatReturnsList());//and forward this request to jsp

on jsp

<c:forEach var="data" item="dataList">
    ${data}
</c:forEach>
Sign up to request clarification or add additional context in comments.

Comments

1

Correcting Jigar Joshi:

request.setAttribute("dataList",methodThatReturnsList());//and forward this request to jsp

But this is not a parameter. The request parameters can only be strings (or string arrays), and are generated when you submit a form or you attach the parameters in the query string of an url.

2 Comments

How can I convert this arraylist into a string and split all the key value pairs for the shown below: [[bitValue=2, name=Families], [bitValue=32768, name=Close to the Beach], [bitValue=512, name=Central Location]]
Do you really need it? Where do you obtain the mappings from? Perhaps it's enough to send bitValues=2,512,32768 . But, if they are bitValues, you can just send bitValues=33282. If you really need to send this information, you could send: list_bitValues=2,512,32768&list_Names=Families,Central Location,Close to the Beach and recover the values with String.split() -- BUT: What is really your problem? I have the feeling that you are not following a good approach.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.