How-To Set Up Web Application Support in Intellij Idea
How-To Set Up Web Application Support in Intellij Idea
This How-to describes setting up web application support in IntelliJ IDEA as well as
environment details crucial for this support to properly function.
Introduction
Introduction
The following features are available when the web application support is set up:
Related documents:
IDEA Help: Web Application Options, Web Application Debugging Options, JSP and
Servlets Support.
How-to Series: How-to Manage JSP files in IntelliJ IDEA, How-to Create Servlets in
IntelliJ IDEA.
Please, keep in mind - this document provides only details critical for running/debugging
your web application using IDEA. Please refer to Tomcat documentation for more details
on its installation/configuration instructions.
1. Consider that you already have a ready web application and its files are located in the
C:\projects\web folder.
2. Download and install Tomcat 4.0.x. At the moment, IDEA supports web application
running/debugging using popular web server Tomcat, version 4.0.x. Versions 4.1.x and
higher are NOT supported.
3. Now you should explain Tomcat where your web application is located and how to
distinguish one web application from another when your server receives a request (you
might have tons of web applications located on your hard drive). To do it, edit
server.xml , a file located in the conf folder of the Tomcat installation:
Anywhere within a Host tag (but not within its child tags) create a Context tag.
If you edit in IDEA, it will look as follows:
The path attribute is used to explicitly and uniquely identify a particular web
application for processing by a web server. Let's name the web application
"WebAppl".
To later call your web application from a browser, its URL should contain the path
value right after the web server address.
The docBase attribute indicates where these pages are physically located.
The path can be either an absolute path or a path relative to the default document
root directory (for Tomcat - webapps).
This is how the resulting context tag should look for our sample application.
The tag looks very simple. But it has enough data for Tomcat to identify
unambiguously your web application and to know where to search for its files.
1. We keep considering the case when your web application files are located in the
C:\projects\web folder.
2. Check that there is a C:\projects\web\WEB-INF folder. If not, create it, because any
particular web application in your project should have its own WEB-INF folder.
3. In the WEB-INF folder of your web application create a file named web.xml.
4. web.xml is the web application deployment descriptor. It defines everything about your
application that a server needs to know.
The tags servlet and servlet-mapping are associated with each other by the
common tag servlet-name which uniquely identifies a particular servlet.
The servlet-class tag within servlet contains a fully qualified name of a servlet
class. The url-pattern tag within servlet-mapping translates a particular request
URI to the specified servlet class.
In the section How to call your web application from browser you will learn
how to use this mapping.
1. Add your web application folder to your project path. Make sure that a WEB-INF folder is
located within this directory.
2. These steps are required only if you are going to work with servlets:
Make sure that the default package containing your servlets is added to the
project's sourcepath.
In the WEB-INF folder create the classes directory and provide it for IDEA as a
compiler output path.
3. Add servlet.jar (for instance, the one located in the common/lib folder of the Tomcat
installation) to your project classpath.
For more details, see section Web Application Options in IDEA Help.
Call the WebApp dialog pressing the Add button. Specify a name for your web
application and a path to the web application folder created in the Step 1.
Press the plus icon to create a new Run/Debug configuration (there is none for
the new web application).
Select a desired web application from the drop-down list (since you can have
more than one web-application in your project).
The default settings for the application server, debugee host, and debugee port
are rather common. But you can change them should they not suit you.
Set the Catalina home for a directory where the Tomcat server is located.
Configuration file settings should be then automatically configured to
Catalina_home/conf.
6. The value of the Application context path field depends on the Tomcat configuration
you are using. There are two configurations possible:
The first configuration allows to run/debug your web application using either IDEA or
Tomcat.
<Context path="/WebAppl"
Tomcat Configuration Sample
docBase="C:\projects\web" debug="0"/>.
The second is useful when you want to run/debug your web application under IDEA only
and do not need to get into Tomcat configuration details.
Web application is launched from IDEA only
7. Write and compile (if necessary) your web-application code. Web application samples
are given in the How-to Manage JSP files in IntelliJ IDEA and
How-to Create Servlets in IntelliJ IDEA.
2. In the address field, you have to define the server address first. For a localhost, type
"http://localhost:8080".
3. Then add the context path of the web application you want to start. In our case, we
keep considering the sample web application above. Its context path is "/WebAppl".
4. The third part of the URL is a bit tricky. It is different for servlets and JSP's.
For servlets, you need to type a value of the url-pattern. The request URI for
calling "YourServlet" (as given in the sample web.xml above) will look like "http:/
/localhost:8080/WebApp/".
You might have several servlets under the same context. To access them
unambiguously, you need to use different URL's. It can be easily done by
modifying the url-pattern value in web.xml for each servlet. For instance,
let's use "/myservlet" instead of "/". In this case, the final URL will look as
"http://your.site.com/WebAppl/myservlet/".