I'm calculating values (based on input from one JSP) in a method in my Controller class and trying to pass it to another different JSP page using ModelAndView but I'm getting a weird NumberFormatException
that I think refers to the value at line 249 from error below, 249: <c:out value="${housepricesList.housePrice}"/>
:
java.lang.NumberFormatException: For input string: "housePrice"
as well as another exception:
2018-03-19 12:39:14.439 ERROR 2452 --- [nio-8080-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [An exception occurred processing JSP page /houseprice.jsp at line 249
246:
247:
248: <c:forEach items="${housepricesList}" var="HousePrice">
249: <c:out value="${housepricesList.housePrice}"/>
250: <c:out value="${housepricesList.number_of_houses}"/>
251: </c:forEach>
252:
I'm getting a latitude and longitude from one JSP page, passing it to a method in my Controller where I use the lat & long values to query a database to return house prices within a 1km radius of initial latitude and longitude. I want to pass this returned information (housePrice
and number_of_houses
) to another JSP page. However the page won't load and the errors above are displayed in the console.
Controller Class
@RequestMapping(value = "/parseHousePrice", method = RequestMethod.POST)
public ModelAndView parseHousePrice(@Valid HousePrice housePriceObject,
@RequestParam("latitude") double latitude,
@RequestParam("longitude") double longitude) {
//Initialising HousePriceObject
housePriceObject = new HousePrice();
// Passing Lat & Long into method that queries DB
double housePriceAverage = parseHousePrice.ParseHousePrice(latitude, longitude);
// This returns the number of houses within the radius
List<Double> housePriceList = parseHousePrice.getList();
int housePriceListSize = housePriceList.size();
// Storing the returned houseprice and number of houses into HousePrice Obeject
housePriceObject.setHousePrice(housePriceAverage);
housePriceObject.setNumber_of_houses(housePriceListSize);
// Debug that shows the query is working correctly
// Successfully prints the average house price and number of houses
System.out.println("The average house price for this area is: " + housePriceAverage + " based on " + housePriceListSize + " property prices in this area");
// Store the Object into List
List<HousePrice> housepricesList = new ArrayList<HousePrice>();
housepricesList.add(housePriceObject);
// Add the list to the MAV and pass it to JSP page ("houseprice")
ModelAndView map = new ModelAndView("houseprice");
map.addObject("housepricesList", housepricesList);
return map;
}
I have a standard JSP page with the following code that I want to pass the info calculated in the Controller to:
<c:forEach items="${housepricesList}" var="HousePrice">
<c:out value="${housepricesList.housePrice}"/>
<c:out value="${housepricesList.number_of_houses}"/>
</c:forEach>
HousePrice entity class
@Entity
public class HousePrice {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int housePrice_id;
private double housePrice;
private double latitude;
private double longitude;
private int number_of_houses;
//constructors
// getters & setters