0

I am setting the context path in jsp page but it is showing error while running the jsp page.

as shown below.

<c:set var="path" value="${pageContext.request.contextPath}"/>

<% urlName='<c:out value="${path}"/>/tran/handleTransactionResults.do'; %>

${path} is not showing the context path.

3
  • The runtime will simply not interprete the value you set for urlName, it's just a Java String. Does this page compile at all? Commented Oct 31, 2011 at 9:42
  • Then how. Some times it is working..and some times showing error page. Commented Nov 1, 2011 at 10:29
  • My understanding is that @nfechner solved your problem. Commented Nov 1, 2011 at 11:03

1 Answer 1

3

You cannot use JSP tags within a scriptlet. Do it like this:

<c:set var="path" value="${pageContext.request.contextPath}"/>
<% urlName= request.getAttribute("path") + "/tran/handleTransactionResults.do"; %>

Or even easier:

<% urlName= request.getContextPath() + "/tran/handleTransactionResults.do"; %>

If you simply want to output your path, you can use the <%= %> shortcut:

<%= request.getContextPath() + "/tran/handleTransactionResults.do"; %>
Sign up to request clarification or add additional context in comments.

1 Comment

in your first scenario it is displaying for the link as /dnweb/tran/null getting an error. But in Second Scenario request.getContextPath() it is displaying perfectly as /dnweband working fine. and the last one you have given Expression. i did't tried it. Any way thanks. It is working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.