字符串构建器变为html表格式 [英] String builder into html table format

查看:118
本文介绍了字符串构建器变为html表格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个servlet来显示我生成的一个小程序的前端。在这个程序中,我有一个LinkedList调用执行队列,我放在一个字符串构建器中。

I'm creating a servlet to display a front end of a little program I've produced, In this program I have a LinkedList call Execution Queue that I place in a string builder.

 public String getJobsForPrint() {
        Iterator<JobRequest> it = ExecutionQueue.iterator();
        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");

        while (it.hasNext()) {
            JobRequest temp = it.next();
            result.append(this.getClass().getName()).append(" Object {").append(NEW_LINE);
            result.append(" User ID: ").append(temp.getUserID());
            result.append(" Start Date: ").append(temp.getStartDate());
            result.append(" End Date: ").append(temp.getEndDate());
            result.append(" Deadline Date: ").append(temp.getDeadDate());
            result.append(" Department: ").append(temp.getDepartment());
            result.append(" Project Name: ").append(temp.getProjectName());
            result.append(" Project Application: ").append(temp.getProjectApplication());
            result.append(" Priority: ").append(temp.getPriority());
            result.append(" Cores: ").append(temp.getCores());
            result.append(" Disk Space: ").append(temp.getDiskSpace());
            result.append(" Analysis: ").append(temp.getAnaylsis()).append(NEW_LINE);
            result.append("}");
        }
        return result.toString();

在我的servlet端我通过以下方式调用字符串:

on my servlet side I call the string by:

protected void processExecutionQueue(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("<!DOCTYPE html>");
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Execution Queue</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<div>");
    out.println("<div style='position:absolute; top:20px; right: 20px;'><a href='/ProjectAndBackend/index.jsp'>LOGOUT</a></div>");
    out.println("</div>");
    out.println("<p>Queue:</p>");           
    out.println("Execution Queue:" + SystemServlet.getScheduler().getJobsForPrint());               
    out.println("</body>");
    out.println("</html>");
}

所以现在我互相显示字符串,其中包含从链表中获取的所有数据。我想在网页上,能够获取数据并将其放入表中,使其看起来更整洁,而不仅仅是字符串被扔到网页上。

So now I display strings after each other with all the data taken from the linkedlist. I want to on the webpage side, be able to take that data and put it into a table so that it looks neater and not just strings tossed onto the webpage.

如何我会实现一个html来显示字符串的特定元素在某些方面
所以下面的例子我有标题然后数据从字符串中取出元素并继续写出来直到所有数据来自迭代器显示

How would I implement a html to show the specific elements of the string in certain aspects So with example below I have the headers then where the data is take the element from the string and keep writing it out until all the data from the iterator displayed

<table border="1">
<tr>
<th>User ID</th>
<th>Start Date</th>
</tr>
<tr>
<td>User ID DATA</td>
<td>Start Date DATA</td>
</tr>

或者,如果有人可以指导我一个例子,因为我找不到当前的搜索。

Or if anyone can direct me to an example as I can't find any with my current searches.

推荐答案

构建StringBuilder时,请使用HTML标记将每个标记放在一行中。

When you build the StringBuilder use HTML tags to place each in a row.

代码应该是这样的

StringBuilder result = new StringBuilder();
result.append("<tr><td>").append(User ID DATA).append("</td><td>").append(Start Date DATA).append("</td></tr>");

注意:

1.您需要在 processExecutionQueue()方法中创建基本html和表头标题列。
2.只需要在 getJobsForPrint()方法中创建数据行。

1.You need to create the base html and table header columns inside processExecutionQueue() method. 2. Only the data row needs to be created in getJobsForPrint() method.

所以当结果从 getJobsForPrint()传递,它将嵌入到其他HTML文件中。

So when the result is passed from getJobsForPrint() it will be embedded into other HTML files.

希望你能完成代码有这个建议。

Hope you can complete the code with this suggestion.

这篇关于字符串构建器变为html表格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆