Deckard
Deckard

Reputation: 1433

Need to `location.href` value in JSTL(or JSP)

All I need is just <script>location.href</script> value in JSTL(or JSP).

Just same as the web browswers display. But it's not that easy.

I'm using Tiles2 and request.getRequestURL() shows tiles base jsp location like /WEB-INF/tiles/base.jsp...

And I found <%=request.getAttribute("javax.servlet.forward.request_uri")%> shows what I want. https://stackoverflow.com/a/11387378/411615

But still it's not enough. it's not showing protocol and domain. And I searched again.

http://${pageContext.request.localName}<%=request.getAttribute("javax.servlet.forward.request_uri")%>

It looks dirty and does not contain parameters. I would make it like this...

Map<String, String[]> parameters = request.getParameterMap();
    for(String parameter : parameters.keySet()) {
        ...
    }

But it's weird. In javascript it's so simple, but in JSP it's very tough.

Is there any neat way?

My environment isSpring 3.1, Tiles2.

Upvotes: 0

Views: 1174

Answers (1)

ccleve
ccleve

Reputation: 15809

The Request object is all you get on the server side. There's no way to know what was in the original href link because the browser sends the fully assembled URL to the server. Your options are 1) use some javascript trickery on the client side to send the original href as a parameter or header value, or 2) poke around in the Request object to get what you need. 2) is better.

Upvotes: 2

Related Questions