mardi 29 avril 2014

how to send an array of numbers from servlets to a a javascript


Vote count:

0





actually i want a server to send a list of numbers to a client and want the client to run >the javascript on its machine and send the result to server and server will verify whether >it is correct or not. how can we do this???....plzzz help package folder;




// Import required java libraries import java.io.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Enumeration;
import javax.servlet.http.*; // Extend HttpServlet class
public class hey extends HttpServlet{ // Method to handle GET method request.
public int ipToLong(String ipAddress,HttpServletResponse response) throws IOException {

String[] ipAddressInArray = ipAddress.split(":");
PrintWriter out= response.getWriter();
int result = 0;
for (int i = 0; i < ipAddressInArray.length&& result<100; i++) {
out.println(ipAddressInArray[i]);
int power = 7 - i;
int ip = Integer.parseInt(ipAddressInArray[i]);
result += ip * Math.pow(256, power);

}

return result%100;
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{// Set response content type
PrintWriter out= response.getWriter();
response.setContentType("text/html");

String title ="Using GET Method to Read Form Data";
String docType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://ift.tt/kkyg93\">";
out.println(docType + "<html>\n"+ "<head><title>"+
title +"</title></head>\n"+ "<body onload=\"factor()\" bgcolor=\"#f0f0f0\">\n"+
"<h1 align=\"center\">"+ title +"</h1>\n"+
"<ul>\n");
out.println(" <script type=\"text/javascript\" language=\"JavaScript\">" +
"\n"+"function factor(){"+"\n"+"var start=result;"+"\n"+"for(;start>=0;start--)\n"+
"document.write(start+1);}"+"</script>");
out.println("</body></html>");


//int addressAsInt = ByteBuffer.wrap(addr).getInt();
Enumeration headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements())
{ String paramName =(String)headerNames.nextElement();
out.print("<tr><td>"+paramName+ "\n");
String paramValue = request.getHeader(paramName);
out.println("<td> "+ paramValue +"</td></tr>\n");
}
out.println("</table>\n</body></html>");
String addr=request.getRemoteAddr();
int result=ipToLong("0:0:0:0:21:12:12:21",response);
out.println(addr+"\nip to long"+result);
int[] num=new int[result];
int Min=0,Max=result;
for(int i=0;i<result;i++)
{
num[i]=Min + (int)(Math.random() * ((Max - Min) + 1));
out.println(num[i]+"\n");
}
String now=new Date().toString();
out.println(now);

}
// Method to handle POST method request.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
doGet(request, response); }

}


asked 47 secs ago






Aucun commentaire:

Enregistrer un commentaire