File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Getting base tag url with pageContext.request.contextPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting base tag url with pageContext.request.contextPath" Watch "Getting base tag url with pageContext.request.contextPath" New topic
Author

Getting base tag url with pageContext.request.contextPath

kiran badi
Greenhorn

Joined: Oct 26, 2009
Posts: 26
I am using base tag and pulling out the webapplication context path to it like this so that all links in the page becomes relative to this path,i am doing something like below,

<base href="${pageContext.request.contextPath}">

which resolves to " /mydomain"/ in IE and base tag looks like this <base href="/mydomain"/> in IE and in other browers like ff/chrome/opera/safari it resolves to "/mydomain" and base tag here looks like <base href="/ourstory">

however all links resolves perfectly fine in IE and when I click on any link, it opens perfectly fine with path http://localhost:8080/mydomain/link1.jsp but the same link when checked via other browser like FF/Opera/chrome/safari it says page not found and gives me 404 error.The same link path now looks like http://localhost:8080/link1.jsp in those browsers.

what is that i am doing wrong here ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61002
    
  65

It's IE that's doing it wrong -- that shouldn't work. The base tag's href value should have the entire absolute base URI starting with http:// (or https:// as appropriate).

This information is also available from various methods on the request.

From the HTML4 Specification:
href = uri
This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kiran badi
Greenhorn

Joined: Oct 26, 2009
Posts: 26
Ok for a second let me assume that IE 9.04 is broken, and its resolving something which it should not.

<base href="${pageContext.request.contextPath}"> this piece of code leads me to <base href="/mydomain"> with other browsers,

so I need to have something like <base href="http://localhost:8080${pageContext.request.contextPath}"> to make all links work ? Is this correct ?

I know for sure that hardcoding <base href="http://localhost:8080/mydomain/"> works perfectly but I dont want it this way.

but again I am not able to figure out when base url is /mydomain ,why are links directly going to root directory or its just that base tag is broken

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61002
    
  65

kiran badi wrote:I know for sure that hardcoding <base href="http://localhost:8080/mydomain/"> works perfectly but I dont want it this way.

Read what I wrote again:
bear wrote:This information is also available from various methods on the request.


kiran badi wrote:but again I am not able to figure out when base url is /mydomain ,why are links directly going to root directory or its just that base tag is broken

Have you read what I wrote? Using anything other than a full absolute URI is invalid. So naturally, it's not going to work correctly.
kiran badi
Greenhorn

Joined: Oct 26, 2009
Posts: 26
I think I missed your point.Thanks for highlighting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting base tag url with pageContext.request.contextPath