Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing CRUD services for JSP/Servlet Application - Problems with read operations
    primarykey
    data
    text
    <p>I am currently working on a website that incorporates JSP's, servlets and some CRUD database services. I am stuck on the <strong>read</strong> portion of the CRUD, as I am unable to get the desired effects.</p> <p>I am connected to a database and am able to insert data from the website without any trouble. What I am trying to do now is to have a select/option box in the JSP call on a row from the database, and to have the corresponding columns of the row translate on the next page. However, I am unable to get more than one row from the option box to appear. The code is listed below.</p> <p>Bean class:</p> <pre><code>public class ReadBean { protected String title; protected String author; protected String text; public String getTitle() { return title; } public void setTitle(String newTitle) { title = newTitle; } public String getAuthor() { return author; } public void setAuthor(String newAuthor) { author = newAuthor; } public String getText() { return text; } public void setText(String newText) { text = newText; } } </code></pre> <p>Controller:</p> <pre><code>@WebServlet(urlPatterns = { "/com/defaultValidate/ReadController" }) public class ReadController extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ReadBean reader = new ReadBean(); String address; if (request.getParameter("ReadConfirm") != null) { try { Connection connect = ConnectionManager.getConnection(); String SQL = "SELECT * FROM prayers ORDER BY prayerTitle DESC"; PreparedStatement ps = connect.prepareStatement(SQL); ResultSet rs = ps.executeQuery(); while (rs.next()) { request.getSession().setAttribute("ref", reader); reader.setTitle(rs.getString("prayerTitle")); } } catch (Exception e) { } address = "ReadConfirm.jsp"; } else if (request.getParameter("ReadView") != null) { address = "ReadView.jsp"; } else { address = null; } RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); } } </code></pre> <p>And then the corresponding jsp page that the controller responds to:</p> <pre><code>&lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt; &lt;%@include file="MenuHeader.jsp"%&gt; &lt;/div&gt; &lt;div id="mainBorder"&gt; &lt;/div&gt; &lt;div id="mainBody"&gt; &lt;table id="mainTable"&gt; &lt;tr&gt; &lt;td id="sidebar"&gt; &lt;h2&gt;Options&lt;/h2&gt; &lt;ul&gt; &lt;/ul&gt; &lt;/td&gt; &lt;td id="mainContent"&gt; &lt;h2 id="contentHeader"&gt;Select a prayer&lt;/h2&gt; &lt;form action="ReadController"&gt; &lt;table border="1" width="1" cellspacing="5" cellpadding="5"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;select name="prayer_id"&gt; &lt;c:forEach var="ReadController" items="${ref.title}"&gt; &lt;option value=""&gt;${ref.title}&lt;/option&gt; &lt;/c:forEach&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" name="ReadView" value="View"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/form&gt; &lt;td id="imageBar"&gt; &lt;/td&gt; &lt;/table&gt; &lt;%@ include file="../menuHeaderAndFooter/MenuFooter.jsp" %&gt; </code></pre> <p>I am definitely not an expert, but I think I am missing something in between the connection from the controller to the for-each element in the JSP that I am simply stuck on. In case curious, the WEB-XML portion of this section is operational and the ConnectionManager is a simple call to set up the connection to the database. The Glassfish package is the utilized server.</p> <p>If you have any questions about any other portion of the code, let me know as I am quite interested in getting this particular project completed and running as soon and efficiently as possible. I will be happy to provide any additional coding and reference requested. </p> <p>Any assistance on this particular spot is most appreciated and very helpful. Thank you for looking this over. </p>
    singulars
    1. This table or related slice is empty.
    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