1
<c:forEach items="<% EasyLookUp.lookUpList(EasyLookUp.PriceSources); %>" var="priceSourceItem"> ${priceSourceItem } </c:forEach> 

this is my code, but the page display

enter image description here

there is just one record, and the java code did not work. can anybody tell me how to handle it?

2 Answers 2

2

Don't use scriptlets:

Write a Servlet that forwards to your JSP resource. In that Servlet's service(..) method (or the HttpServlet's doXXX(..) method), add a request attribute with the return value of your EasyLookup method.

request.setAttribute("lookupResult", EasyLookUp.lookUpList(EasyLookUp.PriceSources)); // forward to JSP 

Then use EL to resolve the attribute in your JSP

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

5 Comments

I got my solution:<% pageContext.setAttribute("PriceSources", EasyLookUp.lookUpList(EasyLookUp.PriceSources)); %> <c:forEach items="${PriceSources }" var="priceSourceItem"> ${priceSourceItem } </c:forEach> but I think your solution is better, but not fit for me.
@jesse Yes, you are using page attributes, which are a scope more restrictive than request attributes. If you take anything away from my answer, it should be this: don't use scriptlets.
your anwser is excellent, we should avoid scriptlets, but the attributes in my bean is all original, it can not display on page.
@jesse Sorry, I did not understand. What did you mean by bean and original? You mean you don't know what type lookUpList will return?
for example country, the column in bean is countryId, just like 1, 2... but on page, it should show as "US", "UK". My English is not good~ I don't know how to express it accurately
1

In foreach loop of jstl there is no need to pass the list with jstl tag

<c:forEach items="${EasyLookUp.PriceSources}" var="priceSourceItem"> ${priceSourceItem } </c:forEach> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.