1

I'm trying to send the variable average review from controller to view and show a number of stars equal with average review.

The problem is that I don't know how to loop through received variable and java code doesn't recognize that variable. I tried with a foreach from JSTL, but there is no list of objects; I want a classic for loop.

Here is my controller:

@RequestMapping(value = "/viewDetails", method = RequestMethod.GET)
public ModelAndView viewProductDetails(HttpServletRequest request) {
int productID = Integer.parseInt(request.getParameter("id"));
// irrelevant code goes here
 double averageReview= reviewDAO.getAverageReview(productID);
 modelAndView.addObject("averageReview",averageReview);
 return modelAndView;
 }

This is my view page, where I tried to loop:

  <p>
      <c:set var = "averageReview" scope = "session" value ="${averageReview}"/>
      <% for(int i=0;i< ${averageReview}; i++){ %>
        <span class="glyphicon glyphicon-star"></span>
      <% } %>
  </p>

1 Answer 1

1

How about this?

  <c:forEach var = "i" begin = "0" end = "${averageReview}">
     <span class="glyphicon glyphicon-star"></span>
  </c:forEach>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.