How do I print a route on the href of my link tag?

0

What I want to do is print the route of the host that I am currently on.

First code

Javascript code

var urlObt;

urlObt = window.location.href;

JSP Code

String url = "<script>document.write(urlObt)</script>";

Impression in href

Form 1

<link rel="stylesheet" href="<%=url%>/CSS/index.css">

Form 2

<link rel="stylesheet" href="<%=out.println(url)%>/CSS/index.css">

Result:

 http://localhost:8080/GIBLO/%3Cscript%3Edocument.write(urlObt)%3C/script%3E/CSS/index.css

Also try directly from the JSP

out.println(request.getAttribute("javax.servlet.forward.request_uri"));

But I came out null

    
asked by David 12.04.2018 в 20:39
source

1 answer

2

The JSP getRequestURL function allows you to obtain the url of the client that makes the request, in your case you can do something similar to this:

<% String url = request.getRequestURL();%>
<link rel="stylesheet" href="<%=url%>/CSS/index.css">
    
answered by 12.04.2018 / 21:28
source