SPEEDTEST.NET MINI with JSP
You can download a neat flash broadband speed test from http://www.speedtest.net/mini.php and put it on your own web site.
It comes with server side scripts in PHP, ASP.NET, and ASP for the upload half of the test. But what if you want it to run on your java web container server such as tomcat or jboss?
Well, I have the solution.
First, for the index.html file simply copy the index-asp.html and change the upload_extension line to read jsp instead of asp:
so.addVariable("upload_extension", "jsp");
Next, you will need to create an upload.jsp file alongside the upload.php and upload.asp files in the speedtest folder.
Here is the code for upload.jsp:
<%
long size = 0;// add length of request header strings
String name = "";
for(java.util.Enumeration e = request.getHeaderNames(); e.hasMoreElements();){
name = (String)e.nextElement();
String value = "";
for(java.util.Enumeration f = request.getHeaders(name); f.hasMoreElements();){
value = (String)f.nextElement();
size += name.length() + value.length() + 3;
//out.print(name+"="+value+"\n");
}
}/*
// add length of request parameter strings
name = "";
for(java.util.Enumeration e = request.getParameterNames(); e.hasMoreElements();){
name = (String)e.nextElement();
String value = "";
String[] values = request.getParameterValues(name);
for(int i = 0; i 0);
}
*/
// add the length of the input stream of uploaded bytes
java.io.InputStream is = request.getInputStream();
if ( is != null ) {
long skip = 0;
do {
skip = is.skip(Long.MAX_VALUE);
size += skip;
} while (skip > 0);
}
response.reset();
response.resetBuffer();
response.setContentType("text/html");
out.print("size="+size);
%>
02.13.09
by Steve Gudmundson