0

我正在我的 Controller 类中的一个方法中计算值(基于来自一个 JSP 的输入),并尝试使用 ModelAndView 将它传递到另一个不同的 JSP 页面,但我觉得奇怪NumberFormatException的是我认为是指第 249 行的值下面的错误,249: <c:out value="${housepricesList.housePrice}"/>

java.lang.NumberFormatException: For input string: "housePrice"

以及另一个例外:

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: 

我从一个 JSP 页面获取纬度和经度,将其传递给我的控制器中的一个方法,在该方法中我使用纬度和经度值来查询数据库以返回初始纬度和经度半径 1 公里内的房价。我想将此返回的信息 (housePricenumber_of_houses) 传递到另一个 JSP 页面。但是页面不会加载,并且上面的错误会显示在控制台中。

控制器类

    @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;
}

我有一个带有以下代码的标准 JSP 页面,我想将在控制器中计算的信息传递给:

<c:forEach items="${housepricesList}" var="HousePrice">     
<c:out value="${housepricesList.housePrice}"/>
<c:out value="${housepricesList.number_of_houses}"/>
</c:forEach>

HousePrice 实体类

@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
4

1 回答 1

0

你试过这个吗

<c:forEach items="${housepricesList}" var="HousePrice">     
    <c:out value="${HousePrice.housePrice}"/>
    <c:out value="${HousePrice.number_of_houses}"/>
 </c:forEach>
于 2018-03-19T13:27:11.290 回答