title: Struts2 How to Return a JSON Response
body: <p>I am currently creating a web-application where the users can fetch tags from the database as JSON,</p>
  
  <p>here is my struts action</p>
  
  <pre><code>public String execute(){
  
  
      Gson gson = new Gson();
      String tagsAsJson = gson.toJson(audioTaggingService.findTagsByName(q));
      System.out.println(tagsAsJson);
  
      return "success";
  }
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>The <code>tagsAsJson</code> is already in a JSON format all I want is to return only that, and not the whole class action itself.</p>
  
  <p>It returns something like this</p>
  
  <p>This is the data I want to return to the user</p>
  
  <pre><code>[{"id":2,"name":"Dubstep","description":"Dub wob wob"},{"id":3,"name":"BoysIIMen","description":"A 1990s Boy Band"},{"id":4,"name":"Sylenth1","description":"A VST Plugin for FLStudio "}]
  </code></pre>
  
  <p>How do I return the <code>tagsAsJson</code> as a r JSON esponse? since that JSON response will be used by the client side code.</p>