• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use servlet output in html

 
amit vaid
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
how do i use the output of a servlet in a html page.
I was writing html in servlets but writing all those
out.println() is very tedious and sometimes u get lost in the code. how do i seperate html and servlet.
thanks and keep smiling
amit
 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a lot of ways to do this, jsp, xml are powerfull things to this. If you are beginning with servlets I recommend you to make classes that represent HTML components and make a library of them. Then construct the HTML page in a separate class and invoque that class from the servlet. Then you servlet has to call a generateCode method that returns the HTML stream from that class, so you have only one out.println in your servlet.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont forget the very powerful and flexible approach of using a template engine. Template Engines (like http://www.webmacro.org/ ) allow you to separate the look and feel issues from the data model by specifying a way of including references to data in HTML "templates" which are processed and filled with data when the page is generated. I would strongly recommend that you look seriously at such systems before getting involved with HTML-generation components.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is some more discussion of template systems, with a WebMacro example, here.
 
ram mohan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the biggest problem we r facing too.Specially we had put lot of effort to embed the HTML pages into the servlet but after sometimes the project manager or client might tell us to make a changes in the layout.As Marsela said we thought of creating classes for the templates but not succeded bcos our presentations varies drastically which compell do drop the idea.Now we r tring to achieve this through a application server call enhydra(www.enhydra.org)which really seperate the application layer and the presentation layer to a great extend.Don't know whether we suceed or not
 
amit vaid
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody
thanks a lot Frank. i was thinking of making a html generation library but u really helped.
thanks a lot.
keep smiling
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic