aspose file tools*
The moose likes Servlets and the fly likes Servlets don't generate HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets don Watch "Servlets don New topic
Author

Servlets don't generate HTML

Doug Gschwind
Greenhorn

Joined: Sep 17, 2000
Posts: 27
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.
Paul Wetzel
Ranch Hand

Joined: Nov 02, 1999
Posts: 107
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

Joined: Sep 17, 2000
Posts: 27
Yes, that does help, and makes good sense. I was wondering if that approach was possible.
Thanks for the help.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
See also the discussion at http://www.javaranch.com/ubb/Forum7/HTML/000628.html which covers this topic in a lot of depth.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Joe Angott
Greenhorn

Joined: Oct 13, 2000
Posts: 7
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets don't generate HTML
 
Similar Threads
how to set link in the executable statement
to pass variable to servlet from html
JSP Popup Object
Servlets and Struts
confusion with all front end technologies - what's in and what's out