0% found this document useful (0 votes)
775 views2 pages

Creating Servlets in IntelliJ IDEA

This document provides instructions for creating a basic servlet in IntelliJ IDEA. It describes creating a servlet class, configuring the web application support and run/debug configurations in IntelliJ, and modifying the web.xml deployment descriptor and Tomcat configuration files. Following these steps allows you to run the servlet and view it at a specified URL.

Uploaded by

Príyöjìt Däs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
775 views2 pages

Creating Servlets in IntelliJ IDEA

This document provides instructions for creating a basic servlet in IntelliJ IDEA. It describes creating a servlet class, configuring the web application support and run/debug configurations in IntelliJ, and modifying the web.xml deployment descriptor and Tomcat configuration files. Following these steps allows you to run the servlet and view it at a specified URL.

Uploaded by

Príyöjìt Däs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

How-to Create Servlets in IntelliJ IDEA

This How-to briefly describes how to create a servlet in IntelliJ IDEA, basing on a servlet
sample.

Creating a Basic Servlet Sample


How-to Make It Run

Related documents:
IDEA Help: Web Application Options, Web Application Debugging Options, JSP and
Servlets Support.
How-to Series: How-to Set up Web Application Support in IntelliJ IDEA, JSP How-to

in IntelliJ IDEA.

Creating a Basic Servlet Sample


1. Tomcat 4.0.x is used as a web-server.
2. In any default package of your project, create a package named "myServletPackage".
Let's consider, that that its full path is "C:\web\src\myServletPackage".
3. Create a new class in that package as follows:

package myServletPackage;
import [Link].*;
import [Link];
import [Link].*;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response

PrintWriter out = [Link]();


[Link]("Hello, this is a servlet!!!");
}
}

To speed up development process you can create a specific File Template for servlets
using Options | File Templates dialog.

How-to Make It Run


1. Set up the Web Application Support as described in the How-to Set up Web
Application Support in IntelliJ IDEA. Some settings need to be adjusted further to
conform with the present How-to .
2. Prior to going further, please, make sure that your web application folder (in our case "C:/web/src/") has the following structure of subfolders:

3. Make sure that "C:\web\src\" is added to your project's sourcepath, and "C:\web\WEBINF\classes\" is specified as an output path.
4. If there is no [Link] in the WEB-INF folder, create it as shown in the next step.
5. Create a file named [Link] in the WEB-INF folder.
Sample [Link] (your web application deployment descriptor).
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2
<web-app>
<servlet>
<servlet-name>MyServletName</servlet-name>
<servlet-class>[Link]</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServletName</servlet-name>
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>
</web-app>

The servlet-class tag should contain the fully qualified name of your servlet class.
If you have already created [Link], replace it with the sample one. More details on
[Link] you can find in the How-to Set up Web Application Support in IntelliJ IDEA,
section Creating minimal [Link] for your servlet and in the Tomcat documentation.
6. Add the following context to [Link] (the Tomcat configuration file) within the Host
tag.
<Context path="/testAppl" docBase="C:\web"/>
More details on contexts you can find in the How-to Set up Web Application Support in
IntelliJ IDEA, section Tomcat configuration details and in the Tomcat documentation.
7. Set up run/debug configuration for your web application in IDEA (if you haven't done it
before) as described in How-to Set up Web Application Support in IntelliJ IDEA.
8. Compile MyServlet.
9. Run the web application. To see how it works, type "[Link]
myservlet/" in the browser address field.

You might also like