-1

I have a problem when I desplay the process in jsp I use the following code:

public ArrayList<String> getProcessusList(){

     ArrayList<String> ss=new ArrayList<String>();
     String st="";
 try {
        String line;
        Process p = Runtime.getRuntime().exec
                (System.getenv("windir") +"\\system32\\"+"tasklist.exe");
        BufferedReader input =
                new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((line = input.readLine()) != null) {
            String[] se=line.split(" =\n");
            for(String sd:se){ss.add(sd);}
        }


        input.close();
    } catch (Exception err) {
        err.printStackTrace();
    }
 return ss;
}

and in jsp file the code is:

<body>
  ArrayList <String>processArray=p.getProcessusList();
  <%for(String se:processArray){
  String []s=se.split(" ");
  for(String sd:s){%><%=sd %>&nbsp;<% }%> <br><% } %>


  </body>

Output:

enter image description here

but I want to a format more user friendly,can you help me?

Ravi
  • 30,829
  • 42
  • 119
  • 173
ofloflofl
  • 205
  • 3
  • 6
  • 12

4 Answers4

1

My solution, some hard code:

public ArrayList<String> getProcessusList(){

        ArrayList<String> ss=new ArrayList<String>();
        try {
            String line;
            Process p = Runtime.getRuntime().exec
                    (System.getenv("windir") +"\\system32\\"+"tasklist.exe");
            BufferedReader input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = input.readLine()) != null) {
                String[] se=line.split(" =\n");
                for(String sd:se){
                    String[] sa = sd.split("\\s\\s+");
                    if (sa.length>1)
                        ss.add(sd);
                }
            }
            input.close();
        } catch (Exception err) {
            err.printStackTrace();
        }
        return ss;
    }

JSP file:

<%
ArrayList<String> processArray=p.getProcessusList();
%>
<table border="1" cellspacing="0">
    <thead>
        <tr>
            <%
            String se = processArray.get(0);
            String[] sa = se.split("\\s\\s+");%>
            <%for (int j=0;j<sa.length;j++){ 
            if(j==1){%>
            <th>PID</th>
            <th>Session Name</th>
            <%} else {%>
            <th><%=sa[j] %></th>
            <%}} %>
        </tr>
    </thead>
    <tbody>
        <%for (int i=1;i<processArray.size();i++){ 
        se = processArray.get(i);
        sa = se.split("\\s\\s+");%>
        <tr>
            <%for (int j=0;j<sa.length;j++){
            if(j==1){
                String ssa[] = sa[j].split(" ");%>
            <td><%=ssa[0] %></td>
            <td><%=ssa[1] %></td>
            <%}else{ %>
            <td><%=sa[j] %></td>
            <%}} %>
        </tr>
        <%} %>
    </tbody>
</table>
0

Take a HTML table and add rows(tr) and td's to get proper structure.

Further you can do some styling to that with CSS.

Using scriplets in jsp is outdated and highly discouraged .Use JSTL instead of Scriplets

Mock Code

   <c:forEach items="${element}" var="myCollection">

    <tr>
        <td><c:out value="${element.field}"/></td>

    </tr>
</c:forEach>

Prefer to read : How to avoid using scriptlets in my JSP page?

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

Add html table (or div) and use JSTL to generate it.

Alex
  • 11,451
  • 6
  • 37
  • 52
0

Try StringUtils

StringUtils.rightPad(sd,30);
newuser
  • 8,338
  • 2
  • 25
  • 33