Getting Started with JSP without XML Code in Eclipse
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.
Example Project Download
This is an example project created with the approach described in this article. You may try this first.
Prepare the Environment
- Download Tomcat (currently 9.0). I use zip version. No configuration.
Create Project
- 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.xml
in the last page. Of course just leave it as is.
Write Your Code
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.
(Optional) Using JSTL or Whatever Libraries
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 pom.xml
.