I am trying to develop a very simple hit counter user servlet. I know how to store, retrieve and update the counter. However I have problems displaying the counter? As the counter is inserted into the middle of a webpage, I am pretty sure I only need to output a small portion of html to the calling page. The webpage itself will contain the html, body, header tags, etc.... At the calling page I placed a link to the counter servlet by inserting an image tag and pointing the source of the image to my servlet. At the servlet end, I set the contenttype to text/html and define the printwriter. However nothing is displayed at the calling page when I write the output from the servlet. Can anybody enlighten me?
Undoubtedly the browser is expecting an image and you are sending text/html - it is not surprising that it does not know what to do with it. My servlets book has a chapter on using servlets to create images and other resources on the fly. (other servlets books do to but we don't talk about THEM) Bill
It's your use of the IMG tag which requires the image. When the browser sees such a tag, it tries (naturally enough) to retrieve an image from the specified URL. If it is given back something which is not an image, then it can't display it.
if you are referencing your servlet directly like this you might try this...write a .js file on the server(simply var counter=x and in the html page include this js file and display the variable as plain text on your page ....ideally the whole page should come from the counter servlet but i've tried this other method and it works manav