title: How to pass JSON response from struts 2 action class to HTML page
body: <p>I am working on struts 2 with JSON response<BR/>
  Below is my code<BR/></p>
  
  <p><strong>ACTION CLASS</strong></p>
  
  <pre><code>public class JSONDataAction implements ServletRequestAware{
  
      private String firstName;
      private String lastName;
  
      protected HttpServletRequest request;
  
      public String execute() {
  
          System.out.println("FIRST NAME IN ACTION CLASS IS::"+firstName);
          System.out.println("LAST NAME IN ACTION CLASS IS::"+lastName);      
  
          request.setAttribute("temp", "temp data");  
  
          return "success";
     }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setServletRequest(HttpServletRequest request) {
          this.request = request;
      }
  
      public HttpServletRequest getServletRequest() {
          return request;
      }
  }
  </code></pre>
  
  <p><strong>struts.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE struts PUBLIC
      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
      "http://struts.apache.org/dtds/struts-2.0.dtd"&gt;
  
  &lt;struts&gt;
      &lt;constant name="struts.devMode" value="true" /&gt;
  
      &lt;package name="jsonView" namespace="/" extends="struts-default,json-default"&gt;
  
         &lt;action name="getJSONResult" class="com.javatechig.struts2web.actions.JSONDataAction"&gt;
             &lt;result name="success" type="json"&gt;/pages/details.html&lt;/result&gt;
         &lt;/action&gt;
  
     &lt;/package&gt;
  &lt;/struts&gt;
  </code></pre>
  
  <p><strong>employee.html</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          &lt;h4&gt;
              Struts 2 HTML5 Example
          &lt;/h4&gt;
  
          &lt;form action="getJSONResult" method="post"&gt;
              Enter first name: &lt;input type = "text" name="firstName"&gt;&lt;br&gt;
              Enter last name : &lt;input type = "text" name="lastName"&gt;&lt;br&gt; 
              &lt;input type="submit"&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>details.html</strong></p>
  
  <pre><code> &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;Details&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
        EMPLOYEE DETAILS :::  
  &lt;/body&gt;
  &lt;/html&gt;  
  </code></pre>
  
  <p>I have added the struts2-json-plugin-2.3.24.jar to the lib folder as required<br/></p>
  
  <p>When I submit the form(employee.html), the form data is captured in action class (JSONDataAction) 
  and I see the json response in browser as shown below<br/></p>
  
  <p><strong>{lastName":"User", firstName: "Test"}</strong><br/>
  I have the following doubts<br/></p>
  
  <ol>
  <li>Why details.html is not displayed on the browser(I see only json
  response on the browser).</li>
  <li><strong>Request attribute - temp is not present in the json response. How to
  pass request attribute in json response.</strong></li>
  <li>How to process json response in details.html.<br/></li>
  <li>How to pass the JSON response to the different views(HTML5) based on
  result type returned from action class.</li>
  </ol>