How to make a youtube link as embed?

118 Views Asked by At
<%
String song = request.getParameter("songname");
String band = request.getParameter("band");
String url = request.getParameter("url");
%>
<div align="center">
    <br><br>  <% out.print(band + " - " + song); %><br><br>
    <iframe width="560" height="315" src="<%out.print(url);%>" frameborder="0" allowfullscreen></iframe>
</div>
<%
%>

Let's say url i get is like this https://www.youtube.com/watch?v=kXYiU_JCYtU i want to make it look like https://www.youtube.com/embed/kXYiU_JCYtU this so i can put it at src=""

1

There are 1 best solutions below

1
On BEST ANSWER

You can use the replace() method:

<% out.print(url.replace("watch?v=", "embed/")); %>