当我在jsp中显示进程时,我遇到了问题 我使用以下代码:
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;
}
在jsp文件中代码是:
<body>
ArrayList <String>processArray=p.getProcessusList();
<%for(String se:processArray){
String []s=se.split(" ");
for(String sd:s){%><%=sd %> <% }%> <br><% } %>
</body>
输出:
但是我想要一种更加用户友好的格式,你能帮助我吗?
答案 0 :(得分:1)
我的解决方案,一些硬代码:
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文件:
<%
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>
答案 1 :(得分:0)
选择HTML table
并添加行(tr
)和td's
以获得正确的结构。
此外,您可以使用CSS对其进行styling
。
在jsp中使用scriplets已经过时且非常气馁。使用JSTL代替Scriplets
模拟代码
<c:forEach items="${element}" var="myCollection">
<tr>
<td><c:out value="${element.field}"/></td>
</tr>
</c:forEach>
答案 2 :(得分:0)
添加html表(或div)并使用JSTL生成它。
答案 3 :(得分:0)
StringUtils.rightPad(sd,30);