4

In my controller I have code like this:

List<FeesReceiptIntegrationModel> FRIList = feesReceiptIntegrationService.listInstituteWiseCollectionSummary(model, request);

model.addAttribute("FRIList", FRIList);

I want to access this FRIList and its fields in Scriptlet of JSP page. I tried something like this:

String fcash = request.getParameter(FRIList.cashamount);

but it does not work.

List myMap = (ArrayList) request.getAttribute("FRIList.cashamount");

I don't want to access this via JSTL tags but I would like to access this only in scriptlet.

Can anybody tell me how this can be achieved?

Santhosh
  • 8,181
  • 4
  • 29
  • 56
Manoj Sharma
  • 47
  • 1
  • 5
  • You put in model list "FRIList", so you can get it in jsp like that: `List myMap = (ArrayList) request.getAttribute("FRIList");` and than do what you want with this list. – glw Aug 28 '15 at 07:25
  • i am access like this List myMap = (ArrayList) request.getAttribute("FRIList.cashamount"); System.out.println("ooooo oo "+ myMap); but till now i can't access ..... myMap show null value.. – Manoj Sharma Aug 28 '15 at 07:46
  • @ManojSharma I suppose you use the `spring` framework . Are you using any view templates for your front-end ? – Santhosh Aug 28 '15 at 08:12
  • For front end i am using jsp,jstl.. – Manoj Sharma Aug 28 '15 at 08:56

2 Answers2

1

Using scriplets is a bad idea. Try to avoid using java codes inside JSP page.

You can use JSTL c:forEach for your purpose

Simple example

<c:forEach items="${FRIList}" begin="0" end="1" var="test">
${test.cashamount}
</c:forEach>
SpringLearner
  • 13,738
  • 20
  • 78
  • 116
0

You cant print the values in the list as it is, you need to iterate them after you get the list from the model. As said,

I don't want to access this via JSTL tags but I would like to access this only in scriptlet

<%  List<FeesReceiptIntegrationModel > myMap = (ArrayList<FeesReceiptIntegrationModel >) request.getAttribute("FRIList");
    for(FeesReceiptIntegrationModel obj : myMap  ){
    obj.getcashamount(); // your getter method here
    }
%>

but it is not advisable to use the scriptlets, please have a look at How to avoid Java code in JSP files?

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56