[java] What does this expression language ${pageContext.request.contextPath} exactly do in JSP EL?

I have a web app, where I have different navigation anchor tags such as Home, Profile and etc.

What I want:

When I press anchor tags like home or profile. I just want to ensure that current user gets its information in that Tags/JSP Page.

Sample Example that I am trying:

<a  href="${pageContext.request.contextPath}/JSPAddress.jsp">Profile</a>

This question is related to java jsp el

The answer is


use request.getContextPath() instead of ${pageContext.request.contextPath} in JSP expression language.

<%
String contextPath = request.getContextPath();
%>
out.println(contextPath);

output: willPrintMyProjectcontextPath


Include <%@ page isELIgnored="false"%> on top of your jsp page.


For my project's setup, "${pageContext.request.contextPath}"= refers to "src/main/webapp". Another way to tell is by right clicking on your project in Eclipse and then going to Properties:

enter image description here


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to jsp

Difference between request.getSession() and request.getSession(true) A child container failed during start java.util.concurrent.ExecutionException The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path Using if-else in JSP Passing parameters from jsp to Spring Controller method how to fix Cannot call sendRedirect() after the response has been committed? How to include js and CSS in JSP with spring MVC How to create an alert message in jsp page after submit process is complete getting error HTTP Status 405 - HTTP method GET is not supported by this URL but not used `get` ever? How to pass the values from one jsp page to another jsp without submit button?

Examples related to el

Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable Adding external resources (CSS/JavaScript/images etc) in JSP How does EL empty operator work in JSF? javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean How to use && in EL boolean expressions in Facelets? How do I check two or more conditions in one <c:if>? The representation of if-elseif-else in EL using JSF Use JSTL forEach loop's varStatus as an ID What does this expression language ${pageContext.request.contextPath} exactly do in JSP EL? How to access at request attributes in JSP?