ST - Creating the Servlet Class
- Create the source folder
- Right-click "tasklist" project folder
- New -> Source Folder
- Project name should be "tasklist"
- Folder name is "tool/src/java"
- Click "Finish"
- Creating the package for the Servlet
- Right-click "tool/src/java"
- New -> Package
- Source folder should be "tasklist/tool/src/java"
- Package Name "org.sakaiproject.tool.tasklist"
- Adding in servletapi
- Right-click "tasklist" project folder
- Java Build Path
- "Add Variable..."
- Select "MAVEN_REPO" and click "Extend..."
- Browse to "servletapi -> jars -> servletapi-2.4.jar"
- Creating the Servlet class
- Right-click the previously created package
- Name is "TasklistTool"
- Enter "javax.servlet.http.HttpServlet" as the Superclass
- Under "Which method stubs would you like to create?", clear all options
- Click "Finish"
You should now have a basic Servlet that looks like this:
package org.sakaiproject.tool.tasklist; import javax.servlet.http.HttpServlet; public class TasklistTool extends HttpServlet { }
package org.sakaiproject.tool.tasklist; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import java.io.PrintWriter; import java.io.IOException; public class TasklistTool extends HttpServlet { /** * Respond to navigation / access requests. * * @param req * The servlet request. * @param res * The servlet response. * @throws ServletException. * @throws IOException. */ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html; charset=UTF-8"); PrintWriter out = res.getWriter(); out.println("<h1>Sakai Tasktool</h1>"); out.println("Hello, "+ req.getRemoteAddr()); } }