Reputation: 11331
jsp` I would like to know my request url, but I tried this and it doesnt work to me
<script>
$url = getRequestURL();
.....
So I am wondering what's the way to get the url?
btw I didnt actually learn jsp so not sure where to look for reference, is this script called jsp script or anything?
Thank you
Upvotes: 0
Views: 2456
Reputation: 1108632
You can let JSP EL print it as if it's a JavaScript variable as follows:
<script>
var url = '${pageContext.request.requestURL}';
// ...
</script>
But why don't you just grab it by JavaScript API directly?
<script>
var url = window.location.href;
// ...
</script>
Note that this code is JavaScript, which is completely different language than Java/JSP. As to learning JSP, start taking a look in our JSP tag wiki page (to get to it yourself, just put your mouse above the tag which you've put below the question yourself and then click the info link in the black pop box, almost every other bit self-respected tag has a wiki page like this, so has JavaScript also one).
Upvotes: 3