Page 4 of 5
How to Start Tomcat Manually
If you have successfully configured Tomcat, you should have a bin folder of Tomcat. Remember that you need to download the Tomcat from Apache website in the form of zip file. Do not download the .exe file as it would be good if you have a manual hands-on experience on this. It should help you to understand how Tomcat works.
I have extracted my Tomcat into C:\tomcat-5.5.16. Thus, I should have a bin folder that is C:\tomcat-5.5.16\bin.
If you pay attention carefully, you would see there is startup.bat and shutdown.bat. These two files are used to start Tomcat and shutdown Tomcat respectively.
Double click on startup.bat, a new Tomcat console should open. Watch the console carefully and you will see something interesting.
You should see that it displays �Deploying web application archive MyFirstServlet.war�. Tomcat always checks its webapps folder whether is there any WAR file. If so, it will extract it and deploy it to its container so that we can run it after Tomcat started. Tomcat will be started if you have seen the message �Server startup in N ms�. If you do not have any WAR file, the above message should not be displayed.
Now, open your browser and go to http://localhost:8080.
This means that we have started Tomcat correctly. As we have already deployed our MyFirstServlet, execute it by http://localhost:8080/[yourwebappname] so it would be http://localhost:8080/MyFirstServlet.
Awesome! Try to press Submit button, it should do nothing as we have not specified any action in our <form></form> tag. Next, we need to modify our index.jsp to call our Java Servlet to greet the user and to redirect the user to the success page.
Please remember not to shutdown the Tomcat by clicking on the close window on the Tomcat console. Please use the shutdown.bat instead as it helps Tomcat to gradually shutting down itself.
Now, let�s create our Java Servlet. You can right click on the src folder (this is your source folder) and choose New and Others. A wizard will be prompted to you to configure your Java Servlet.
Go to the Web, choose Servlet and press Next button.
In this wizard, you may define the package for your Java Servlet. Normally, we use Package to group a few Java files that has the same functionalities. For example, if I have StringUtil.java for String manipulation and EncodingAlgorithmUtil.java for encoding, I will locate them under the same package called �com.mycompanyname.util� as they both are actually utility classes. So as this is our first Java Servlet, let�s create one package called �com.mycompany.servlet�. The class name is basically your Java Servlet name. To make it self-explanatory, I name it GreetingServlet. You can leave other configuration as they are.
Then press Next button.
In the second step of the Java Servlet configuration, you may or may not provide any description that you want for your Java Servlet. Initialization Parameter is extremely useful if your Java Servlet need to have initial value before being executed. The URL mapping is used to identify on how the Java Servlet should be called. This is the URL that is called in your <form></form> tag in JSP file. If you set the URL Mapping into /test/GreetingServlet, you need to call it as /test/GreetingServlet from your <form></form> tag in your JSP file.
In the last step of Java Servlet configuration, we can keep them as they are. This wizard allows you to modify your Java Servlet�s methods. Press Finish button and we have created a non-functional Java Servlet.
If you have followed correctly, you should have a GreetingServlet.java similar to the illustration below.
|
Hai guys. This is the best, best, best website which gives me an idea for using the webtools platform of eclipse.