开发者

Should I use JSP or servlet to generate HTML table?

I need to dynamically generate html table and insert in the jsp page and would like to know the best way to开发者_如何学Python do this. Theses are the options I am debating over:

  • Generate a string which contains html tags in Servlet and set in attribute to forward to the jsp page
  • Create object which contains data to generate table and set in the attribute to forward to jsp page, jsp page will use tag library to generate the table


The latter. Servlets should not know or care about presentation logic. JSTL is usually enough to render the model from within the JSP, but if greater complexity is necessary, use a custom taglib to render the data.


The second option is the best one. A simple example:

<table>
<!-- some headings here -->
<c:forEach items="${tableRows}" var="row">
   <tr>
      <td>${row.foo}</td>
      <td>${row.bar}</td>
   </tr>
</c:forEach>
</table>

The servlet should not be aware of HTML

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜