extends GenericServlet : GenericServlet « javax.servlet « Java by API






extends GenericServlet

import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class GetKey extends GenericServlet {
  public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    String key = getInitParameter("key");
    String host = req.getServerName();
    int port = req.getServerPort();

    if (!keyFitsServer(key, host, port)) {
      out.println("Pirated!");
    } else {
      out.println("Valid");
    }
  }

  private boolean keyFitsServer(String key, String host, int port) {
    return true;
  }
}


           
       








Related examples in the same category

1.GenericServlet: getInitParameterNames()
2.GenericServlet: getInitParameter(String arg0)
3.GenericServlet: init()
4.GenericServlet: getServletContext()