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.

There's no "link" needed - it doesn't even make sense to "link" them.
The first is a template - it's an example that shows you the "standard" code and where to add your own code.
The second is an example of using that template - it has the same standard code and adds your code in the right place.

You can now completely ignore the first, and just get on with completing the second.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.