title: How to Get data from JSON request in struts2
body: <p>I'm trying to get data from a JSON request in Apache Struts 2.<br>
  I've tested with this url: <a href="http://date.jsontest.com/" rel="nofollow">http://date.jsontest.com/</a>.<br>
  In <code>StrutsJsonClientAction.java</code> file, line</p>
  
  <pre><code>System.out.println(result);
  </code></pre>
  
  <p>prints this to the console:</p>
  
  <pre><code>{ "time": "12:04:12 PM", "milliseconds_since_epoch": 1431086652240, "date": "05-08-2015"}
  </code></pre>
  
  <p>I want to know how to show this result in <code>result.jsp</code></p>
  
  <p>Today, I found there is <a href="https://spring.io/guides/gs/consuming-rest/" rel="nofollow">resttemplate</a> can use in spring,I want to know are there the tools like restemplate in struts2 that I can use??</p>
  
  <p>My current solution: <code>StrutsJsonClientAction.java</code></p>
  
  <pre><code>package com.example.action;
  
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.URL;
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts2.ServletActionContext;
  import com.opensymphony.xwork2.ActionSupport;
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts2.ServletActionContext;
  
  public class StrutsJsonClientAction extends ActionSupport{
  
      private static final long serialVersionUID = 1L;
  
      private final String url="http://date.jsontest.com/";
  
      public String execute() throws Exception {
  
          HttpServletRequest request= ServletActionContext.getRequest();
  
          request.setCharacterEncoding("utf-8");
  
          URL myUrl = new URL(url);
          //System.out.println(myUrl.toString());
          HttpURLConnection connection = (HttpURLConnection) myUrl.openConnection(); 
          connection.connect();
  
          BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8")); 
          String result=""; 
          String temp=null;
  
          while ((temp=reader.readLine())!= null) { 
              result=result+temp;
          } 
  
          System.out.println(result);
  
          return SUCCESS;
      }
  
  }
  </code></pre>
  
  <p>file <code>struts.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"&gt;
  &lt;struts&gt;
      &lt;package name="struts2" extends="struts-default"&gt;  
          &lt;action name="GoToGetApi" class="com.example.action.StrutsJsonClientAction"&gt;  
              &lt;result&gt;/resault.jsp&lt;/result&gt;  
          &lt;/action&gt;  
      &lt;/package&gt;  
  &lt;/struts&gt;    
  </code></pre>