我正在尝试获取一个url - 我得到的地方 - 以及我存储在两个变量中的一些值。我将这些变量放入arrlist。 现在我想在我的jsp页面上打印出该数组列表。限制:我希望一次打印前50个值,然后在几秒钟后打印下一个100个值。 但是之前的值不应该显示,然后显示下一个50值,并且应该显示最终不显示的起始值。
这是我的jsp代码
<div class="push">
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="1" bordercolor='66A8FF'>
<%
URL url;
try {
// get URL content
String a="http://122.160.81.37:8080/mandic/commoditywise?c=paddy";
url = new URL(a);
URLConnection conn = url.openConnection();
// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
StringBuffer sb=new StringBuffer();
String inputLine;
ArrayList<String> list1=new ArrayList<String>();
ArrayList<String> list2=new ArrayList<String>();
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
String s=inputLine.replace("|", "\n");
s=s.replace("~"," ");
StringTokenizer str = new StringTokenizer(s);
while(str.hasMoreTokens())
{
String mandi = str.nextElement().toString();
String price = str.nextElement().toString();
list1.add(mandi);
list2.add(price);
}
}
%>
<%
String item1 = null;
int i=0;
int j=0;
for ( i= 0; i < list1.size(); i++)
{
%>
<tr bgcolor="0F57FF" style="border-collapse:collapse">
<td width="50%" height="50px" align="center" style="font-size:24px"><font color="#fff"><%= list1.get(i)%></font></td>
<%
for ( j = 0; j < list2.size(); j++)
%>
<td width="50%" height="50px" align="center" style="font-size:24px"><font color="#fff"><%= list2.get(j)%></font></td>
</tr>
<%
}
br.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
%>
</table>
</div>
如何实现输出?
提前致谢
答案 0 :(得分:0)
您必须将您的列表存储在会话中,而不是刷新您的jsp一段时间。每次你有两个列表,一个在会话中,第二个是你当前获取的列表。
现在,如果你想从arraylist中删除常见(显示新添加的)元素,你必须这样做。
1.制作两个阵列(新旧)的联合
2.制造出它们的交叉点
3.从联合中扣除交集以获得结果
// suppose you have two list as below
List<Integer> list1 = Arrays.asList(1, 2, 3, 4);
List<Integer> list2 = Arrays.asList(2, 3, 4, 6, 7);
// Prepare a union
List<Integer> union = new ArrayList<Integer>(list1);
union.addAll(list2);
// Prepare an intersection
List<Integer> intersection = new ArrayList<Integer>(list1);
intersection.retainAll(list2);
// Subtract the intersection from the union
union.removeAll(intersection);
// Print the result
for (Integer n : union) {
System.out.println(n);
}