Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want partial page updates, then there is <strong>no other way</strong> than using JavaScript/Ajax <em>(okay, you can in theory do so with a client side application like a Java applet, but that's plain clumsy)</em>. JSP runs on the server side, generates a bunch of HTML and sends it to the client side. On the client side, there is no means of any Java/JSP code. All you can do is to grab JavaScript for a bit dynamics. JavaScript is able to send HTTP requests/responses asynchronously and access/manipulate the HTML DOM tree.</p> <ul> <li>Learn the basic JavaScript concepts: <a href="http://www.tizag.com/javascriptT/" rel="nofollow noreferrer">JavaScript tutorial</a></li> <li>Learn the Ajax concepts: <a href="http://www.tizag.com/ajaxTutorial/" rel="nofollow noreferrer">Ajax tutorial</a></li> <li>Learn the jQuery which makes Ajax/HTMLDOM very easy and crossbrowser compatible: <a href="http://jquery.com" rel="nofollow noreferrer">jQuery</a></li> <li>Learn Servlets: <a href="https://stackoverflow.com/tags/servlets/info">our Servlets wiki page</a></li> </ul> <p>Now you can work through the examples provided in <a href="https://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax">How to use Servlets and Ajax?</a> to grasp the general concepts so that you can reapply it for your own use case. Here's a basic kickoff example:</p> <pre><code>&lt;div id="serverTime"&gt;&lt;/div&gt; &lt;script&gt; setTimeout(function() { $.get("timeServlet", function(response) { $("#serverTime").text(response); }); }, 1000); &lt;/script&gt; </code></pre> <p>with the following in servlet's <code>doGet()</code></p> <pre><code>response.setHeader("Cache-Control", "no-cache,no-store,must-revalidate"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("text/plain"); response.getWriter().write(new Date()); // Use SimpleDateFormat if necessary. </code></pre>
 

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