Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way I can think of is to use the MVC approach. Once the user clicks on the URL, you can have a servlet verify that the object id is valid. In other words, the servlet will contain all your logic. So, in jspPage1</p> <pre><code>&lt;c:forEach items="${objects}" var="object1"&gt; &lt;tr&gt; &lt;td&gt;&lt;a href=" &lt;c:url value='/checkId' &gt; &lt;c:param name='id'value ='${object1.ID}' /&gt; &lt;/c:url&gt; "&gt;${object1.text}&lt;/a&gt; &lt;/tr&gt; &lt;/c:forEach&gt; </code></pre> <p>Then you register a servlet called CheckIdServlet in web.xml </p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;checkId&lt;/servlet-name&gt; &lt;servlet-class&gt;CheckIdServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;checkId&lt;/servlet-name&gt; &lt;url-pattern&gt;/checkId&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>Since you are passing the parameters in the url all you need to do is override the doGet(...) method </p> <pre><code>public class CheckIdServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //do your id checking to make sure it's a number or if id value is actually in the database //if either condition not met, you could redirect back to jsppage 1 or however you want to do //handle response.sendRedirect("/jsppage1.jsp"); //or if id is valid RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsppage2.jsp"); dispatcher.forward(request, response); //Keep in mind this is pseudocode so make sure to add your if conditions above } </code></pre> <p>Finally, in jsppage2 you simply display your object id </p> <pre><code>&lt;h1&gt;${param.id}&lt;/h1&gt; </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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