Hi,
I have a little servlet which does the following:
package Services;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Random;
public class Service extends HttpServlet{
private String getContinent() {
Random random = new Random();
int continent = random.nextInt(6);
switch (continent) {
case 0: return "EUROPE";
case 1: return "ASIA";
case 2: return "AUSTRALIA & NEW ZEALAND";
case 3: return "AFRICA";
case 4: return "SOUTH AMERICA";
default: return "NORTH AMERICA";
}
}
private int timeZone() {
Random random = new Random();
return random.nextInt(12);
}
private int getTimeStamp() {
Random random = new Random();
return random.nextInt(Integer.MAX_VALUE);
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/xml");
PrintWriter out = response.getWriter();
out.println("<?xml version='1.0' encoding='UTF-8'?>");
out.println("<time-zones>");
out.println("<timestamp>"+getTimeStamp()+"</timestamp>");
out.println("<continent>"+getContinent()+"</continent>");
out.println("<timezone>"+timeZone()+"</timezone>");
out.println("<latitude>"+request.getParameter("lat")+"</latitude>");
out.println("<longitude>"+request.getParameter("long")+"</longitude>");
out.println("</time-zones>");
out.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}
This servlet should do its job, when a user logs in. After that I have to parse that xml response. How can I do that? Where will be available the data from the out.println statements? I wrote an xml parser too, but it works with filenames... Should I store the output somewhere in a file?
Help me out, please
Thanx in advance.