プロが教えるわが家の防犯対策術!

javax.el.PropertyNotFoundException: Property 'id' not found on type java.lang.Stringをいうアラームが消えません。
どなたか<c:out value="${var5.id}"/>を表示する方法を教えて下さい。

「hoge.jsp」

<%@ page language="java" contentType="text/html; charset=Windows-31J" pageEncoding="Windows-31J" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:if test="${itemSize != 0}">
<table border="0" >
<c:forEach var="var5" items="table">
<tr>
<td width="30" ><c:out value="${var5.id}"/></td>
<td width="210"><c:out value="${var5.name}"/></td>
<td width="50" ><c:out value="${var5.price}"/></td>
<td width="50" ><input type="text" name="count" value="1" size="3"/></td>
</tr>
</c:forEach>
</table>

「hoge.java」

public class hoge extends HttpServlet{

private static final long serialVersionUID = 1L;

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("Windows-31J");
int id = 0;
String name = null;
int price = 0;
try{
table3 = new ArrayList<Object>();
id = Integer.parseInt(request.getParameter("id"));
name = request.getParameter("name");
price = Integer.parseInt(request.getParameter("price"));
hogeBean hoge = new hogeBean();
hoge.setId(id);
hoge.setName(name);
hoge.setPrice(price);
table3.add(hoge);
request.getSession().setAttribute("table", table3);
}catch(Exception e){
throw new ServletException(e);
}
getServletContext().getRequestDispatcher("/hoge.jsp").forward(request,response);
}
private List<Object> table3;
public List<Object> getTable3() {
return table3;
}
}

「hogeBean.java」

public class hogeBean{
private int id;
public int getId(){
return id;
}
private String name;
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public void setId(int id){
this.id = id;
}
private int price;
public int getPrice(){
return price;
}
public void setPrice(int price){
this.price = price;
}
}

A 回答 (1件)

>javax.el.PropertyNotFoundException: Property 'id' not found on type java.lang.String


エラーメッセージのとおり、Stringクラスにはidというプロパティはないからです。
><c:forEach var="var5" items="table">
これでは"table"という文字列に対してループ処理することになります。なので、
<c:forEach var="var5" items="${table}">
としなければいけないです。

<c:out value="${var5}"/>
などとして、var5にどんな値が入っているのかを確認すれば気付けるのではないかなーと思います。
    • good
    • 2

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています


このQ&Aを見た人がよく見るQ&A