• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets don't generate HTML

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I certainly understand and agree with placing all the presentation specifics in a JSP, leaving the fill in the blank info as the responsibility of the Servlet/backend.
Suppose you have the situation where the result of an end user's actions is a variable length (in terms of number of rows) HTML table. How can the JSP/Servlet be designed so that the Servlet (or elsewhere in the non-presentation logic) doesn't generate HTML? Seems like in this case the Servlet needs to render the table row, table data, and end table row constructs for each row.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jsp can make a call to some class/object that may return a variable length list (lets just say a vector). the jsp code might look like this

so now nobody really needs to know how long the vector is (unless of course the vector is null but lets assume it will always return at size>=1). This is a pretty simple example but the process and reasoning are still valid for more complex examples where what is displayed is a result set from SQL.
hope this helps
paul
 
Doug Gschwind
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that does help, and makes good sense. I was wondering if that approach was possible.
Thanks for the help.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See also the discussion at http://www.javaranch.com/ubb/Forum7/HTML/000628.html which covers this topic in a lot of depth.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could also use the java code in your jsp to test (if lenth > 0 or !null) for the presence of data and the enclose the HTML display portion pertinent to the data in curly braces. This way the code in the table tags only gets seen by the browser when the test is true.
reply
    Bookmark Topic Watch Topic
  • New Topic