简体   繁体   中英

How to access model attribute fields in JSP scriptlet?

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?

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>

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM