当我在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>
输出:
但是我想要一种更加用户友好的格式,你能帮助我吗?
4 回答
我的解决方案,一些硬代码:
JSP文件:
获取
HTML table
并添加行(tr
)和td's
以获得正确的结构 .此外,你可以使用CSS做一些
styling
.在jsp中使用scriplets已经过时且非常不鼓励 . 使用JSTL而不是Scriplets
模拟代码
更喜欢阅读:How to avoid using scriptlets in my JSP page?
添加html表(或div)并使用JSTL生成它 .
试试StringUtils