This example show you how to obtain web application context path in JSP using Expression Language (EL) feature of JSP. To get the context path we can utilize the pageContext
, it is an implicit object that available on every JSP pages. From this object you can get access to various object such as:
servletContext
session
request
response
To get the context path value you will need to read it from the request.contextPath
object. This contextPath
can be useful for constructing a path to you web resources such as CSS, JavaScript and images. Libraries that you’ll need to enable the JSP Expression Language (EL) in your JSP Pages, which usually already included in a Servlet container such as Apache Tomcat.
Here is our context-path.jsp
file.
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>JSP - Context Path</title>
</head>
<body>
Web Application Context Path = ${pageContext.request.contextPath}
</body>
</html>
Maven dependencies
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024
Dear Wayan Saryada,
I am really happy to read this and appreciate it. Could you suggest me with example.
I have
http://localhost:8085/call4admission/admin/home/home.jsp
. I want to change this url tohttp://localhost:8085/call4admission/admin
orhttp://localhost:8085/call4admission/admin/home
how to do?Kindly Help me.
Ranjan Kumar Gochhayat
Hi,
Why do you want to change the URL? what is the main purpose that you are trying to achieve?