One potential problem with this method is that, if the browser's 'Back' button is
clicked to return to the opening Web page, the initial name entered is still visible.
This doesn't really matter in this particular example, but, for other (repeated) data
entry, it probably would. In order to overcome this problem, we need to force the
browser to reload the original page, rather than retrieve it from its cache, when a
return is made to this page. There is an HTML META tag that will do this, but the
tag varies from browser to browser. However, the following set of tags will satisfy
most of the major browsers:
<META HTTP-EQUIV="Pragma" CONTENT="no cache">
<META HTTP-EQUIV="Cache-control" CONTENT="no cache">
<META HTTP-EQUIV="Expires" CONTENT="0">
These should be placed immediately after the <HEAD> tag on the initial
Continuing now with the approach of gradually adding to the complexity of our
servlets, the next step is to carry out some processing of the data entered and display
the results of such processing. The next example accepts two numbers, adds them
and then displays the result. Since there are multiple inputs, we shall use the POST
method. In addition, an HTML table has been used for laying out the page elements
Firstly, the code for the initial Web page…
<!-- SimpleAdder.html -->
<META HTTP-EQUIV ="Pragma" CONTENT="no cache">
<META HTTP-EQUIV ="Cache-control"
<META HTTP-EQUIV ="Expires" CONTENT="0">
<FORM METHOD=POST ACTION="AdderServlet">
<TD><INPUT TYPE="Text" NAME="Num1"
<TD><INPUT TYPE="Text" NAME="Num2"