A few days ago, I learned how to use JSP in class. The teacher told us to use NetBean, but I am an old eclipse man. So I tried to find a way to create JSP projects in Eclipse, also without ugly XML code (
web.xml). It was not troublesome but very easy.
This is an example project created with the approach described in this article. You may try this first.
- Download Tomcat (currently 9.0). I use zip version. No configuration.
- Maybe first check whether Eclipse Java EE extension is installed.
- Then in Eclipse, switch to Java EE perspective.
- Select “File - New Project - Dynamic Web Project” (if I remember correctly).
- Configure your Tomcat and choose it.
- Click OK all the way. There is an option, which is unchecked by default, to generate
web.xmlin the last page. Of course just leave it as is.
Yes, that is all. Without web.xml, you need to set the mapping using servlet annotation. There are
@webServlet, … and some other ones I do not remember. Just search for them and you will find.
If you want to use some JSP libraries like JSTL, following is the easiest way. Right click your project, select “Configure - Convert to maven project”. So you can use maven to manage dependencies. You open to
pom.xml and click dependencies, then add JSTL or whatever you want and manage it (Seems like it is optional. I just manage it and it is always OK). This approach requires you have full maven repository index in your Eclipse. If you do not have, search for it. It will save you a lot of time to add dependencies. Or you can manually search
JSTL pom and copy that silly dependency string into your