• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why encodeURL not including Context name

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In my Servlet, I used below code,

out.println("<html><body");
out.println("<a href=\""+response.encodeURL("/PriceRangeServlet")+ "\"> Click me </a>");
out.println("</body></html>");

In response, when I click on Click me link, I am getting HTTP Status 404 - /PriceRangeServlet because of it is ignoring context path of my application. And in URL, it's shown as http://localhost:8080/PriceRangeServlet
instead of http://localhost:8080/testweb/PriceRangeServlet. Here, testweb is my application name(context name).

Why it is Ignoring context name. If I used RequestDispatcher in Servlet, it is working fine.
What is the difference between these two. And how I fix the above Issue.

Thanks,
Siva
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The documentation of encodeURL doesn't say that it will add the context path to the passed path. The encodeURL is used for session tracking when Cookies are disabled. It adds the JSESSIONID to the end of the request path. You'll have to use request.getContextPath to add the context path to your link...
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jami siva wrote:Hi,

In my Servlet, I used below code,

out.println("<html><body");
out.println("<a href=\""+response.encodeURL("/PriceRangeServlet")+ "\"> Click me </a>");
out.println("</body></html>");

In response, when I click on Click me link, I am getting HTTP Status 404 - /PriceRangeServlet because of it is ignoring context path of my application. And in URL, it's shown as http://localhost:8080/PriceRangeServlet
instead of http://localhost:8080/testweb/PriceRangeServlet. Here, testweb is my application name(context name).

Why it is Ignoring context name. If I used RequestDispatcher in Servlet, it is working fine.
What is the difference between these two. And how I fix the above Issue.

Thanks,
Siva



You can also use taglibrary
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
...
<c:url value="/PriceRangeServlet" />
...
which add context path to the url and add jsessionid if it is needed
Br
Michal
 
reply
    Bookmark Topic Watch Topic
  • New Topic