Image not refreshing in JSP java dynamic web project
<p>Building a web application <strong>where the user can search a word and a relevant image will be returned.</strong> But whenever the <strong>query is changed, the image does not</strong>. What is going on here?</p>

<p>User searches "cat" and image comes back. But then stays like this after the first query.
<a href="https://i.stack.imgur.com/ikp6r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ikp6r.png" alt="enter image description here"></a></p>

<p><strong>DefineWord.jsp</strong></p>

<pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%&gt;
&lt;%@ page import="googleAPI.*" %&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
&lt;title&gt;Define&lt;/title&gt;

&lt;link rel="stylesheet" type="text/css" href="css/bootstrap.css"&gt;

&lt;link rel="stylesheet" href="css/bootstrap-lightbox.min.css"&gt;
&lt;link rel="stylesheet" href="css/bootstrap-lightbox.css"&gt;

&lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;&lt;/script&gt;
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="js/includeNAV.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt;
&lt;style&gt;
    .fit_image img {
        max-width: 100%;
        max-height: 100%;
    }
    .fit_image {
        width: 400px;
        height: 200px;
    }
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
    &lt;div id="includedNav"&gt;&lt;/div&gt;


    &lt;div class="container"&gt;
        &lt;form id="searchForm" method="get" action="LinkServlet"&gt;
            &lt;fieldset&gt;

                &lt;input id="s" type="text" name="query" /&gt; &lt;input type="submit"
                    value="Submit" id="submitButton" /&gt;


            &lt;/fieldset&gt;
        &lt;/form&gt;
    &lt;/div&gt;
    &lt;br /&gt;
&lt;!--    Requests attributes from servlet --&gt;

    &lt;div class="container"&gt;
&lt;%--        &lt;%=request.getAttribute("links") %&gt; --%&gt;
        &lt;br /&gt; ONE LINK:
        &lt;div class="fit_image"&gt;
        &lt;img src="&lt;%=request.getAttribute("onelink")%&gt;"/&gt;
&lt;/div&gt;





    &lt;/div&gt;
    &lt;script
        src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script
        src="//blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"&gt;&lt;/script&gt;
    &lt;script src="js/bootstrap-image-gallery.min.js"&gt;&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>LinkServlet.java</strong></p>

<pre><code>package googleAPI;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/LinkServlet")
public class LinkServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public LinkServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.removeAttribute("onelink");

        // Get query from user through http parameter

        String query = request.getParameter("query");
        String results = google.psuedomain(query);

        // Put results string into a ArrayList so that the jsp can dynamically
        // call each image
        String[] urlAry = results.split("\n");
        ArrayList&lt;String&gt; ar = new ArrayList&lt;String&gt;();
        ar.clear();
        ar.removeAll(ar);
        for (int i = 0; i &lt; urlAry.length; i++) {
            ar.add(urlAry[i]);
        }

        // Get first element from ArrayList and set attribute
        String onelink = ar.get(0);
        request.setAttribute("onelink", onelink);

        // Set query results to attribute so JSP can call it
        request.setAttribute("links", ar);

        // Forward request back to the same JSP.
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/DefineWord.jsp");
        dispatcher.forward(request, response);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    }

}
</code></pre>

<p><strong>google.java</strong></p>

<pre><code>package googleAPI;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Pattern;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;

public class google {
    static StringBuilder results = new StringBuilder();
    static String finalResults;

    public static String getFinalResults() {
        return finalResults;
    }

    public static void setFinalResults(String finalResults) {
        google.finalResults = finalResults;
    }

    public static String psuedomain(String qry) throws IOException {

        String key = "*********private key************";
        URL url = new URL("https://www.googleapis.com/customsearch/v1?key=" + key
                + "&amp;cx=*********private key************&amp;q=" + qry + "&amp;alt=json");

        // CONNECTION LOGIC
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");
        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
        String output;
        while ((output = br.readLine()) != null) {
            Pattern pattern = Pattern.compile("(?:(?:https?)+\\:\\/\\/+[a-zA-Z0-9\\/\\._-]{1,})+(?:(?:jpe?g|png|gif))");
            Matcher matcher = pattern.matcher(output);
            if (matcher.find()) {
                results.append(matcher.group() + "\n");
            }

        }
        conn.disconnect();
        finalResults = removeDup();
        return finalResults;
    }

    public static String removeDup() {
        String[] tokens = results.toString().split("\n");
        StringBuilder resultBuilder = new StringBuilder();
        Set&lt;String&gt; alreadyPresent = new HashSet&lt;String&gt;();

        boolean first = true;
        for (String token : tokens) {

            if (!alreadyPresent.contains(token)) {
                if (first)
                    first = false;
                else
                    resultBuilder.append("\n");

                if (!alreadyPresent.contains(token))
                    resultBuilder.append(token + "\n");
            }

            alreadyPresent.add(token);
        }
        String result = resultBuilder.toString();
        return result;
    }

}
</code></pre>

<p>Any ideas as to why this might be happening? Thanks for your time. </p>