for(int j =0; j< serial ; j++) { Date dd = new Date(); URLConnection urlConn = (URLConnection)al.get(j); OutputStream os = urlConn.getOutputStream(); os.write(aryByte); os.flush(); os.close(); System.out.println("Send request thread " +Integer.toString(j+1)+" at " +dd); altime.add(dd); } /* * String st_time = "Start time of Url thread "+Integer.toString(j) +"is :"+dd; * */ ArrayList strlist = new ArrayList(); Vector vt = new Vector(); // String fileText = ""; DbConnection db = new DbConnection(); for(int k=0; k <serial ; k++) {
URLConnection urlConn = (URLConnection)al.get(k); InputStream in = urlConn.getInputStream();
vt.add(in); Date dd = new Date(); long time = dd.getTime(); System.out.println("Recieve response of thread " +Integer.toString(k+1)+" at " +dd); String res=""; String ed = "End time of Url thread "+Integer.toString(k+1) +" is :"+dd; Date st_time = (Date)altime.get(k); String st = "Start time of Url thread "+Integer.toString(k+1) +" is :"+st_time; String sp_time = "Total Spend :" +(time-st_time.getTime())+" ms"; String[] list = new String[6]; list[0] = st ; list[1] = ed; list[2] = sp_time; list[3] = res ; list[4] = st_time.toString(); list[5] = dd.toString(); /* try { db.InsertMessage(list, in); } catch (SQLException e) { e.printStackTrace(); }*/ int input; while((input = in.read())!=-1){ res = res + (char)input; } list[3] = res ; in.close(); strlist.add(list); }
PrintWriter out = response.getWriter(); for(int i =0; i < strlist.size(); i++) { String[] temp = (String[])strlist.get(i); // fileText = temp[0]+temp[1]+temp[2]+temp[3]; out.println(temp[0]); out.println(temp[1]); out.println(temp[2]); out.println(temp[3]); out.println("==================================================================="); }
1、jsp网页默认情况下都支持session,如果希望不支持,设置session="false";
2、Servlet通过在客户端浏览器中保存一个session ID来跟踪Session,并保存在cookie中;
3、如果禁止了cookie,Servlet容器将会为每一个jsp请求创建一个不同的Session,这样就失去了跟踪状态的功能;
4、如果想在客户端禁止了cookie的情况下跟踪状态,可以在服务器端使用Servlet容器的重写客户请求的URL的功能来支持Session。
我是想在我的SERVLET中做某个操作让对方的SERVLET以为我的请求来自不同的地方。
不过因为我没有仔细做过,所以也是泛泛而谈。
不过我也谈谈我的看法。
你提到对方服务器是Servlet容器,据我所知,Servlet使用javax.servlet.http.HttpSession接口来实现Session机制,他会根据请求为不同的客户创建不同的HttpSession对象,并分配一个唯一的Session ID。并且在以下的情况中,释放Session的资源:
1、客户端关闭浏览器
2、Session过期
3、服务器端调用HttpSession的invalidate()方法
一般来讲,服务器端会把Session ID写入浏览器的Cookie中,如果不支持,则Servlet会为同一ip的多次重复请求创建不同的Session。
但是服务器端也可以通过重写客户请求的URL,来支持session,而不管你是否支持cookie。这样的话,只要你发送jsp请求的url不变,服务器总是认为来自同一个Session。
也有可能是服务器提供了某种过滤,限制了同一url的重复请求,我猜测。
http://dev2dev.bea.com.cn/bbs/jishudata/ArticleShow.jsp?Id=10
也有可能是服务器提供了某种过滤,限制了同一url的重复请求,我猜测这个猜测是不正确的,当你的JSP重复发送请求,也就是页面重复做POST操作的时候,所产生的SESSION是决然不同的,这个是实践得到的结果。
<form name="loginForm" method="post"
action="<%=response.encodeURL("mailcheck.jsp")%>
若服务器支持重写URL,那么他返回给客户端的源文件中,对应以上代码生成的网页内容为:
<form name="loginForm" method="post"
action="mailcheck.jsp;jsessionid=95493599415695F01771DB6F270F68EF">这也就是说,如果服务器端支持重写URL,页面重复作post操作,产生的session是相同的。根据你的情况判断,服务器端应该没有采用重写URL机制,所以页面重复做post操作的时候产生的session不同。
我在程序中调用了session的invalidate发法, 本地服务器已经重新建立了一个SESSION
但是从远程返回的结果仍然是串行处理的,有点怀疑远程是不是以SESSION来处理的
但是同时开2个不同的浏览器返回的确实是并行的,已经被弄糊涂了。
throws ServletException, IOException {
String example = request.getParameter("address");
ArrayList al = new ArrayList();
ArrayList altime = new ArrayList();
int serial = 0;
if(request.getParameter("SerialNum")!=null) {
try {
serial = Integer.parseInt(request.getParameter("SerialNum"));
} catch (Exception e){
response.getWriter().println("Error :"+e.toString());
response.getWriter().println("Serial number is invalid ,please reinput it.");
}
}
for (int i=0; i<serial ; i++) {
URL url = new URL(example);
URLConnection urlConn = url.openConnection();
urlConn.setRequestProperty("Content-Type","text/xml");
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
al.add(urlConn);
}
String str = "";
str = request.getParameter("XML");
byte[] aryByte = str.getBytes();
for(int j =0; j< serial ; j++) {
Date dd = new Date();
URLConnection urlConn = (URLConnection)al.get(j);
OutputStream os = urlConn.getOutputStream();
os.write(aryByte);
os.flush();
os.close();
System.out.println("Send request thread " +Integer.toString(j+1)+" at " +dd);
altime.add(dd);
}
/*
* String st_time = "Start time of Url thread "+Integer.toString(j) +"is :"+dd; * */
ArrayList strlist = new ArrayList();
Vector vt = new Vector();
// String fileText = "";
DbConnection db = new DbConnection();
for(int k=0; k <serial ; k++) {
URLConnection urlConn = (URLConnection)al.get(k);
InputStream in = urlConn.getInputStream();
vt.add(in);
Date dd = new Date();
long time = dd.getTime();
System.out.println("Recieve response of thread " +Integer.toString(k+1)+" at " +dd);
String res=""; String ed = "End time of Url thread "+Integer.toString(k+1) +" is :"+dd;
Date st_time = (Date)altime.get(k);
String st = "Start time of Url thread "+Integer.toString(k+1) +" is :"+st_time;
String sp_time = "Total Spend :" +(time-st_time.getTime())+" ms";
String[] list = new String[6];
list[0] = st ;
list[1] = ed;
list[2] = sp_time;
list[3] = res ;
list[4] = st_time.toString();
list[5] = dd.toString();
/*
try {
db.InsertMessage(list, in);
} catch (SQLException e) {
e.printStackTrace();
}*/
int input;
while((input = in.read())!=-1){
res = res + (char)input;
}
list[3] = res ;
in.close();
strlist.add(list);
}
PrintWriter out = response.getWriter();
for(int i =0; i < strlist.size(); i++) {
String[] temp = (String[])strlist.get(i);
// fileText = temp[0]+temp[1]+temp[2]+temp[3];
out.println(temp[0]);
out.println(temp[1]);
out.println(temp[2]);
out.println(temp[3]);
out.println("===================================================================");
}
}
但那个只在IE下可以,而且还需要不停的点,太累,有没方法实现不断提交POST请求?
网上应该有这一类的工具吧,有点象黑客工具了。