Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying html

 
Mark Leong
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

------------------
author of:
 
Mark Leong
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank. Actually I do not want to display graphics, just a plain text counter. I have tried setting the content type to text/plain. Still no results.
Any more help?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
manav kher
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Leong
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank. But is there anyway I could output the result of the text counter to a webpage without using the image tag?
 
Mark Leong
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found an answer to my problem - display the counter in an applet. The applet will talk to a servlet to update the counter which is fed back to the applet. The applet can be configured by the client.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic