简体   繁体   English

如何在JSP中从Stringtokenizer呈现令牌

[英]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. 我有一个格式为CatalogSwitcherInterrupter-active__..falsestrings list ,我想在所附的屏幕快照中的jsp上进行介绍。

在此处输入图片说明

Below is the html snippet for the above html table. 以下是上述html表的html代码段。

 <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. 组件td数据将替换为CatalogSwitcherInterrupter ,属性td数据将替换为active,并且基于字符串, J01,J02,W01,W02 td数据将替换为true或false。 I'll use jstl tags to render this data dynamically. 我将使用jstl标记动态呈现此数据。

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. 已经将StringTokenizer-__..用作分隔符,但它没有提供所需的结果,并且通过增加scriplet标记内的代码而使代码更脏。

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? 现在,我想在这里请求聪明的人,是否有更好的方法使用StringTokenizersplit方法拆分此字符串CatalogSwitcherInterrupter-active__..false并使用jstl标记或最小scriplets呈现在jsp上?

I'm relatively a beginner in java web programming. 我是Java Web编程的初学者。 Any kind of inputs is of great help. 任何形式的输入都会有很大的帮助。

Thanks in advance. 提前致谢。

Are you using an MVC framework? 您正在使用MVC框架吗? Even if you aren't, the MVC approach is better for such tasks. 即使您不是,MVC方法也更适合此类任务。 I'd do the following: 我将执行以下操作:

  1. Create a POJO with all the display fields. 使用所有显示字段创建一个POJO。
  2. Instead of producing a list of strings on the backend produce a list of classes created in #1. 而不是在后端生成字符串列表,而是生成在#1中创建的类的列表。 This would be the controller part of MVC. 这将是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. 在您的jsp输出中,通过简单的foreach循环从后端接收的所有数据。 You can access all the attributes of a POJO that have a getter method in JSTL. 您可以访问JSTL中具有getter方法的POJO的所有属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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