Note that there are some explanatory texts on larger screens.

plurals
  1. POServlet/JSP: Property 'id' not found on type mobile
    primarykey
    data
    text
    <p>1) I have a link in an HTML page which simulates an HTTP <code>GET</code> request.(by manually supplying the query string. This page basically calls a Servlet where a database access is done in its <code>doGet()</code> method. The SQL query is sent as part of the query string. </p> <p><code>http://localhost:8080/prelim_db_test_19_3_2013/md?q=select * from test.mobile</code> (<code>test</code> is the MySQL DB and <code>mobile</code> is the table).</p> <p>2) Then, the results are stored in an ArrayList.</p> <pre><code>ArrayList &lt;mobile&gt; mylist=new ArrayList&lt;mobile&gt; (); mylist.add(new mobile(rs.getInt("id"),rs.getString("name"))); </code></pre> <p>where <code>mobile</code> is simply a class with <code>id</code> and <code>name</code> as class variables (and a constructor as well)</p> <p>3) The <code>ArrayList</code> is then forwarded to another JSP as:</p> <pre><code>request.setAttribute("answer", mylist); request.getRequestDispatcher("info.jsp").forward(request, response); </code></pre> <p>4) Now in the second JSP, I simple use <code>&lt;c:forEach&gt;</code> to iterate and print the table contents:</p> <pre><code>&lt;c:forEach items="${answer}" var="i"&gt; &lt;tr&gt; &lt;td&gt;${i.id}&lt;/td&gt; &lt;td&gt;${i.name}&lt;/td&gt; &lt;/tr&gt; &lt;/c:forEach&gt; </code></pre> <p>Yet, when I run the project, an exception is thrown:</p> <p><code>javax.el.PropertyNotFoundException: Property 'id' not found on type mobile</code></p> <p>at this line:</p> <p><code>request.getRequestDispatcher("info.jsp").forward(request, response);</code></p> <p>Note that the DB access itself works fine when the results are printed to console(so the Servlet gets called too with my query string). Here's my project setup in Eclipse(if there's any problem with the way it's set up):</p> <p><img src="https://i.stack.imgur.com/JYumC.png" alt="enter image description here"></p> <p>What am I doing wrong here?</p> <p><strong>EDIT</strong> <code>mobile.java</code>:</p> <pre><code>public class mobile { int id; String name; public mobile(int i,String n) { id=i; name=n; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload