Showing posts with label jsp-servlet. Show all posts
Showing posts with label jsp-servlet. Show all posts

Tuesday, February 11, 2014

Display tag Pagination, Sorting Example in JSP and Servlet

If you are a Java programmer, writing JSP pages for your web application and doesn't know much about JavaScript, jQuery, CSS and HTML, then display tag is best for creating dynamic tables, pagination, sorting, and exporting data into PDF, Word and Excel format. Display tag is a JSP tag library, where code is written in Java but you can use them like HTML tags e.g. <display></display> . Though display tag is old library, I have always used in JSP for displaying tabular data. It comes with sample CSS as well, which is good enough for many applications. Long time back, I have shared some display tag tips and example, and many of my reader asked me to write about how to do pagination and sorting in JSP page. I haven't really got chance to work on JSP after that, so it took me so long to share this display tag pagination and sorting example tutorial. Anyway, In this tutorial we will not only learn about pagination and sorting but also learn how to display multiple tables using display tag in one JSP file. There is a non obvious detail, which can trouble you if you are also like many programmers, who write code by copying, including me :). If you create another table by just copying the table already exists in page, it may not work, until you remember to provide two different ids or uids. In absence of unique identifier like this, any pagination or sorting activity on one table will also disturb other table. So always remember to provide unique id or uid to each table, created by display tag in same page.
Read more �

Tuesday, September 24, 2013

JSTL forTokens Tag Example - Split String in JSP

JSTL forTokens tag is another tag in core JSTL library to support Iteration or looping. It effectively complements, more useful <c:forEach> tag, by allowing you to iterate over comma separated or any delimited String. You can use this tag to split string in JSP and can operate on them individually. forTokens tag has similar attribute like forEach JSTL tag except one more attribute called delims, which specifies delimiter. For example to iterate over colon separated String "abc:cde:fgh:ijk", delims=":". By the way, forTokens tag also accept multiple delimiter, which means, you can split a big string into token based upon multiple delimiter e.g. colon(:) and pipe (|), This will be more clear, when we will see examples of JSTL forTokens tag in JSP. Rest of attribute e.g. items, var, varStatus, begin, end and step are same, as they are in case of <c:forEach> tag. For quick review, items specify String which needs to be split-ed in token and var hold current String.
Read more �