请看下面的代码

<%--
    Document   : index
    Created on : Feb 7, 2014, 1:03:15 PM
--%>

<%@page import="java.util.Map"%>
<%@page import="java.util.Iterator"%>
<%@page import="analyzer.DataHolder"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1><center>Web Site Analizer</center></h1>
        <br/>
        <form action=http://localhost:8080/WebSiteAnalizer/SiteAnalizer method=post>
            Enter the Percentage (0-100): <input type="Text" name="percentage">
            <br/><br/><br/>

            Enter the Words (Separated from New Line (/n)): <br/>
            <textarea name='wordList' value='wordList'></textarea>
            <br/><br/>

            <input type="submit" value="Submit">

        </form>

        <%@page import="java.util.List" %>
        <%@page import="java.util.ArrayList" %>
        <%@page import="java.util.HashMap" %>

        <%

            List<DataHolder> dataHolder = (ArrayList)request.getAttribute("list");
            HashMap hashMap = (HashMap)request.getAttribute("wordMap");

            if(hashMap==null)
                               {
                out.println("Hashmap null");
            }

            if(dataHolder!=null && dataHolder.size()>0)
            {
               out.println("</br>");
               out.println("<table border='1'><th>Primary Key</th><th>Original Hash</th><th>Matching Words</th><th>Non Matching words</th>");

                for(int i=0;i<dataHolder.size();i++)
                {
                    DataHolder d = dataHolder.get(i);

                    int primaryKey = d.getPrimaryKey();
                    String originalHash = d.getOriginalHash();
                    ArrayList matchingWords = d.getMatchingWords();
                    ArrayList unMatchingWords = d.getUnmatchingWords();

                    StringBuffer matchingWordsStr = new StringBuffer("");
                    StringBuffer unMatchingWordsStr = new StringBuffer("");

                    //Populating Strings
                    for(int m=0;m<matchingWords.size();m++)
                    {

                        Iterator iter = hashMap.entrySet().iterator();

                        while(iter.hasNext())
                        {
                            Map.Entry mEntry = (Map.Entry)iter.next();

                            if(mEntry.getValue().equals(matchingWords.get(m)))
                            {
                                //out.println(matchingWords.get(m)+" : "+true);
                                matchingWordsStr.append(mEntry.getKey());
                                matchingWordsStr.append(",");
                            }
                        }

                    }

                    for(int u=0;u<unMatchingWords.size();u++)
                    {
                        Iterator iter = hashMap.entrySet().iterator();

                        while(iter.hasNext())
                        {
                            Map.Entry mEntry = (Map.Entry)iter.next();

                            if(mEntry.getValue().equals(unMatchingWords.get(u)))
                            {
                                //out.println(matchingWords.get(m)+" : "+true);
                                unMatchingWordsStr.append(mEntry.getKey());
                                unMatchingWordsStr.append(",");
                            }
                        }
                    }


                    out.println("<tr>");

                    out.println("<td>");
                    out.println(String.valueOf(primaryKey));
                    out.println("</td>");

                    out.println("<td>");
                    out.println(originalHash);
                    out.println("</td>");

                    out.println("<td>");
                    out.println(matchingWordsStr);
                    out.println("</td>");

                    out.println("<td>");
                    out.println(unMatchingWordsStr);
                    out.println("</td>");

                    out.println("</tr>");



                }
               out.println("</table>");
            }

        %>
    </body>
</html>


这段代码会生成一个表格,但它确实很大,这意味着宽度太大而无法容纳屏幕。原因是,此代码输入到列中的String值很长。可能是5000到10000个单词,并且一栏中的所有内容都显示在一行中。例如,如果“原始哈希”为10000个字符,则整个内容将显示在一行中。那么,无论如何,我可以为屏幕制作出这个套装的长度吗?

另外请注意,我是开发人员,而不是设计师。我很少使用脚本语言。

最佳答案

用这个CSS打破很长的字眼-

td{
   word-wrap:break-word;
}

09-15 16:46