I would like to program Java servlets using Eclipse and I plan on deploying them using Tomcat. I think I can build the projects using Ant which is bundled with Eclipse. I have the standard Eclipse IDE. What options do I have for doing Servlet development in Eclipse? What changes do I need to make to Eclipse? Do I need to install a plug-in?
How do you develop Java Servlets using Eclipse?
You need to install a plugin, There is a free one from the eclipse foundation called the Web Tools Platform. It has all the development functionality that you'll need.
You can get the Java EE Edition of eclipse with has it pre-installed.
To create and run your first servlet:
- New... Project... Dynamic Web Project.
- Right click the project... New Servlet.
- Write some code in the
- Find the servers view in the Java EE perspective, it's usually one of the tabs at the bottom.
- Right click in there and select new Server.
- Select Tomcat X.X and a wizard will point you to finding the installation.
- Right click the server you just created and select Add and Remove... and add your created web project.
- Right click your servlet and select Run > Run on Server...
That should do it for you. You can use ant to build here if that's what you'd like but eclipse will actually do the build and automatically deploy the changes to the server. With Tomcat you might have to restart it every now and again depending on the change.
bmdhacks is right that if you're using MySQL or PostgreSQL it doesn't matter as much since connections are pretty cheap. But no matter your database you will have speed gains by using persistent connections.
But if you do decide to go with persistent connections you will need to worry about connection timeouts. These will happen at any time during the life of your program depending on your server settings and the amount of traffic you're getting.
ping() is your friend here. And if you need more help, look at how
Apache::DBI does it.