Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The servlet engine creates and keep a single Servlet instance, thread unsafe, for all the web application life.</p> <p>This means, that every property set at the servlet level, will be shared between all the threads (calls, users...) that access these functionality.</p> <p>So you never should set Servlet attributes to handle request or session values.</p> <p>Adiotionally, to send parameters via GET, you should inform them as a key/value collection.</p> <p>This way, you'll be able to acccess these parameters through the getParameter() method of the Request.</p> <p>So, applying to your code:</p> <pre><code>&lt;a href="MyServlet?action=check"&gt;Some Html Code&lt;/a&gt; &lt;a href="MyServlet?action=show"&gt;Some Html Code&lt;/a&gt; </code></pre> <p>Now, you are sending a parameter called "action" to the Servlet. To retrieve it:</p> <pre><code>public class MyServlet extends HttpServlet{ //removed instance level properties protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { String action=request.getParameter("action"); //add some validation code here on the "action" value if(action.equals("check")){ //do some stuff and then put a value (its not random) in the count1 int count1 = 10; //lets say this value its 10 for a user1. request.setAttribute("count", count1); RequestDispatcher disp = getServletContext().getRequestDispatcher("/page1.jsp"); disp.forward(request, response); } else if (action.equals("show")){ //do some stuff and then put a value in the count1 String title = "title"; //same here request.setAttribute("title", title); RequestDispatcher disp = getServletContext().getRequestDispatcher("/page2.jsp"); disp.forward(request, response); } } </code></pre> <p>And that's it.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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