0
 <html:link href="/dnweb/displayFindDeviceId.do" styleClass="small" onclick="appendHref(this)"> 
       <bean:message key="link.find"/>
 </html:link>

The above code having context name as "/dnweb". This is given as hardcoded. But i need it as dynamically.

If you changed the context name to your project. Automatically it has to be changed. How can i do for this.

i have the code as

<html:link href="${pageContext.request.contextPath}/displayFindDeviceId.do"

But this is giving an error.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
Mdhar9e
  • 1,376
  • 4
  • 23
  • 46
  • check this link ...[click][1] [1]: http://stackoverflow.com/questions/2065843/changing-tomcat-web-application-context – Sumit Singh Oct 28 '11 at 10:00

4 Answers4

3

You don't need the pageContext. Simply use ${request.contextPath}

Note that for older versions of JSP you may need to set:

<%@ page isELIgnored="false" %> 

But try to upgrade your servlet container to support a newer version.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • you still haven't answered my question "what error is it giving" – Bozho Oct 31 '11 at 12:45
  • It is giving as error to link 'http://localhost:8080/dnweb/device/$%7Brequest.contextPath%7D/displayFindDeviceId.do But it should be like this below path 'http://localhost:8080/dnweb/displayFindDeviceId.do'. – Mdhar9e Oct 31 '11 at 13:18
  • what's the JSP version? What's on the top of your JSP (jsp directives)? – Bozho Oct 31 '11 at 13:33
  • JSP version: **1.2** '<%@ page language="java" %> <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/tlds/struts-ext.tld" prefix="ext" %> <%@ taglib uri="/WEB-INF/tlds/struts-tiles.tld" prefix="tiles" %> <%@ taglib uri="/WEB-INF/tlds/utility.tld" prefix="util" %> <%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c" %>' these are only i have used to my page. – Mdhar9e Oct 31 '11 at 14:01
  • we can't upgrade the server. We are in project. – Mdhar9e Oct 31 '11 at 14:51
  • `http://localhost:8080/dnweb/device/$%7Brequest.contextPath%7D/displayFindDeviceId.do` it is showing the link as above. But it should be like `http://localhost:8080/dnweb/displayFindDeviceId.do`. – Mdhar9e Oct 31 '11 at 15:03
  • You are doing something very wrong above - you should not have the standard tlds in WEB-INF/tld. And your whole EL is ignored. – Bozho Oct 31 '11 at 15:06
0

i set the context path using html taglib tag i can set the context path using a variable by using scriptliet tags like

i took variable urlName to collect contextPath here.

<jsp:useBean id="urlName" class="java.lang.String" scope="page" />
 <% urlName= request.getContextPath() + "/displayFindDeviceId.do"; %>
 <html:link href="<%=urlName %>" styleClass="small" onclick="appendHref(this)"> 
      <bean:message key="link.find"/>  
 </html:link>

As per this code it is working fine in my localhost.

Thanks to Bozho and JB.

Mdhar9e
  • 1,376
  • 4
  • 23
  • 46
0

${pageContext.request.contextPath} worked for me (spring version 4.3.5.RELEASE and jstl version 1.2). The setting isELIgnored="false" is still needed.

dimirsen Z
  • 873
  • 13
  • 16
0

This is a Struts1 tag, isn't it? If so, then you should use the action or the page attribute to be able to use context-relative (or even module-related) URLs. See http://struts.apache.org/1.x/struts-taglib/tagreference.html#html:link for details.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255