Get HttpServletRequest via Maven repository

Problem

Using Maven build tool, which jar should include to use HttpServletRequest or HttpServletResponse?

Solution

To use HttpServletRequest or HttpServletResponse in a development environment, include servlet-api. jar in your Maven pom.xml file.

pom.xml

  <dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>servlet-api</artifactId>
	<version>2.5</version>
	<scope>provided</scope>
  </dependency>

Put scope as provided, because most j2ee containers have this jar. You need this for complication only, not deployment.

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

7 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ravi Kant Soni
13 years ago

Add this to POM.XML

javax
javaee-api
6.0

Dawny
8 years ago

They changed the artifact id…

javax.servlet
javax.servlet-api
3.1.0
provided

Hospitals in Hyderabad
8 years ago

The idea provided here was very helpful.

Abhishek
10 years ago

It is still using the servlet from jdk. This is causing problem for me.

Douglas Carvalho
13 years ago

Thanks A LOT!
I fogot the scope provided.

A hug.
Doug

Ravi Kant Soni
13 years ago

javax
javaee-api
6.0

Simon
13 years ago

Hi,

Whenever we use the Maven install command, will get the .war file without having the lib folder.

I’ve some doubts to deploy the WAR file into some other Development, Test or Production server where ill get those supported files and run my application.

could you please kindly give me some details.