简体   繁体   中英

How to present tokens from stringtokenizer in jsp

Kind Note: I've tried my best to present this question as clear as possible. In case, if you want more details or if the question is not clear kindly let me know rather downvoting the question, I'll edit for you.

I've a list of strings in this format CatalogSwitcherInterrupter-active__..false and I want to present this on jsp in the attached screenshot.

在此处输入图片说明

Below is the html snippet for the above html table.

 <table border="1"> <tr> <th>Component</th> <th>Properties</th> <th>J01</th> <th>J02</th> <th>W01</th> <th>W02</th> </tr> </table> 

Component td data will be replaced by CatalogSwitcherInterrupter , Properties td data will be replaced by active and J01 ,J02,W01,W02 td data will be replaced by true or false based on the string. I'll use jstl tags to render this data dynamically.

Have used StringTokenizer with -__.. as a delimiter, it didn't give the desired result and making code more dirty by increasing the code inside scriplet tags.

Now, I would like to request smart people here, Is there a better way to split this string CatalogSwitcherInterrupter-active__..false using StringTokenizer or split method and present on jsp using jstl tags or minimal scriplets?

I'm relatively a beginner in java web programming. Any kind of inputs is of great help.

Thanks in advance.

Are you using an MVC framework? Even if you aren't, the MVC approach is better for such tasks. I'd do the following:

  1. Create a POJO with all the display fields.
  2. Instead of producing a list of strings on the backend produce a list of classes created in #1. This would be the controller part of MVC. Pass the created list to the view as an attribute.
  3. In your jsp output all data received from the backend in a simple foreach loop. You can access all the attributes of a POJO that have a getter method in JSTL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM