I'm learning servlets 3.0 through a set of code examples and the purpose of many of the methods is not making any sense to me. Except the service method.
The output is "Hello from MyServlet". But, what's with all the other methods?
@WebServlet(name = "MyServlet", urlPatterns = { "/my" })
public class MyServlet implements Servlet {
What is the line below trying to do?
private transient ServletConfig servletConfig;
@Override
public void init(ServletConfig servletConfig) throws ServletException {
this.servletConfig = servletConfig;
}
@Override
public ServletConfig getServletConfig() {
return servletConfig;
}
@Override
public String getServletInfo() {
return "My Servlet";
}
//This is the only method that makes sense to me. All the others, I have no
idea why they are in here.
@Override
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
String servletName = servletConfig.getServletName();
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.print("<html><head></head>" + "<body>Hello from " + servletName
+ "</body></html>");
}
@Override
public void destroy() {
}
}