Main Tutorials

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.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
7 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ravi Kant Soni
11 years ago

Add this to POM.XML

javax
javaee-api
6.0

Dawny
6 years ago

They changed the artifact id…

javax.servlet
javax.servlet-api
3.1.0
provided

Hospitals in Hyderabad
6 years ago

The idea provided here was very helpful.

Abhishek
8 years ago

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

Douglas Carvalho
10 years ago

Thanks A LOT!
I fogot the scope provided.

A hug.
Doug

Ravi Kant Soni
11 years ago

javax
javaee-api
6.0

Simon
11 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.