However, this isn't the 1990's. Your IDE will do most of your work for you if you like. When we right moused clicked you may have noticed something that I didn't touch on in the last post. Here's a photo of what I'm talking about.
Wait, what?! Add Servlet?! |
Here's step 1 of the wizard:
Basic servlet properties |
Okay so I'm going to create my SayGoodByeServlet in the com.blogger.testing package, since I already have my SayHelloServlet in the same package. On to step 2!
Basic Annotation properties for servlets |
That's better |
The meat and potatoes of the class |
Everything on this final step is fine as is, so I'll click the finish button., the generated code appears in the code editor windows. Here's what it says:
package com.blogger.testing; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class SayGoodByeServlet */ @WebServlet("/Goodbye") public class SayGoodByeServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public SayGoodByeServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } }
As you can see the automatically generated code, is pretty much on par with the code that we wrote just the other day. Now we can remove those TODO comments and put down some actual code that will tell our system what to do. Publish the new information to the server and see the wonderful results.
Having a good start on manually building a servlet really helps you to understand the bits that the wizard is doing for you automatically. So I really recommend getting a peek at how it is done manually and then come and do this and see how it is done automatically.
Cheers!
No comments:
Post a Comment