• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where should the initial HTML code of your page go?

 
Ahmed Bin S
Ranch Hand
Posts: 372
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am a little confused - in all the examples I see, I see the code in doGet or doPost.

However. surely these methods should only be used to handle the requests and how to display the page once the request is handled, and the initial code should go in, maybe, init?

For example, let's say I have a page that is going to display a text box and a button, and when you click the button, it displays the text you entered using the POST method. The HTML for the second part can go in doPost, however, the initial page with the text box and button should be in init, yes? In the book I am looking at, it is in doGet however.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, your servlets shouldn't generate HTML at all. After they are done with their processing they should forward to a JSP to create the HTML views. Please read this article for information on properly structuring Java web apps.

And certainly no HTML is generated in init which is only called once when the servlet goes into service and has no connection to any browser request or response.
 
Ahmed Bin S
Ranch Hand
Posts: 372
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I wasn't aware of the "journal" section - very interesting reading! I am still working through the servlet chapters of my book, once I get to JSP I will read that article.

So just to clarify, if I type in, say, http://news.bbc.co.uk, then a HTTP GET is sent with no parameters, yes?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct.
 
Ahmed Bin S
Ranch Hand
Posts: 372
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic