Hi everyone. I am just learning how to use servlets. I need to make a lotto application. I have this template:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyLottoServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
//Add functionality here to take in the numbers from the request, check that they are valid numbers, sort them, and display them back to the user via the response.
}
}
And this is my Servlet :
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SimpleServlet extends HttpServlet {
/** * Handle the HTTP GET method by building a simple web page. */
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out;
//String [] numbers = new String[6];
//int [] lottoNumber = new int[50];
// set content type and other response header fields first response.setContentType("text/html");
// then write the data of the response
for(int i = 1; i < lottoNumber.length; i++)
System.out.println(i + " " + lottoNumber[i] + " ");
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<H1>" + title + "</H1>");
out.println("<P>This is output from SimpleServlet."); out.println("</BODY></HTML>");
out.close();
}
}
I have to link the two but I am really struggling. I will be very appreciated if someone could give me a hand with it and if it can explain it a bit better to me. Thank you.