Getting an image url from jsp to ajax without jQuery
<p>i have this function in javascript, that i want to show me a diferrent image every time:It gets this image from a jsp(that connects with database through a method)</p>

<p>function myFunction(eventId) {
    xmlhttp=new XMLHttpRequest();</p>

<pre><code>xmlhttp.onreadystatechange= function(){     
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
    {
        document.getElementById("imgevent").style.background = "url('xmlhttp.responseText')  repeat scroll 0 0 / cover ";
    }else{
            document.getElementById("imgevent").innerHTML = "Waiting for getting Picture";
    }
}

xmlhttp.open("GET","pictures.jsp?e="+eventId,true);
xmlhttp.send(); 
</code></pre>

<p>Here is the jsp code:</p>



<pre><code>&lt;% 
    String ev = request.getParameter("e");
    int eventt = Integer.parseInt(ev);
    Ev e = new Ev();
    String img = e.getPicture(eventt);
    response.setContentType("image/jpg");  
%&gt;
</code></pre>

<p>I am not sure how <strong>right is the way that response</strong> server(jsp) back to client(javascript)
(The method that gets the url from database is right)</p>