title: Controller to write contents or msg varaibles to specific iframe
body: <p>I am using an JSP page which has two iframe, one of the iframe in the left pane shows the link's and iframe in the right pane is the display window, when I click on the link in the left iframe, the controller is called, to display the content in the right pane/iframe, but it always display the content in the same pane/left pane/left iframe itself, how to display the contents in the right iframe/display window.</p>
  
  <p>refer to the picture for more details
  <a href="https://i.stack.imgur.com/Tq2yv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tq2yv.jpg" alt="enter image description here"></a></p>
  
  <p>showMessage</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;link rel="stylesheet" type="text/css"
      href="/LDODashBoard/css/mystyle.css" /&gt;
  
  &lt;title&gt;L1 DashBoard page&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;iframe id="mainContent" src="/LDODashBoard/L1SrcLinkPage.htm"   height="500" width=20% scrolling="no"&gt;Main&lt;/iframe&gt;
  &lt;iframe id="displayContent"  src="/LDODashBoard/L1OutputDisplayPage.htm" height="500" width=70% scrolling="no"&gt;Content&lt;/iframe&gt;
  
  
      &lt;h2&gt;${message}&lt;/h2&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>MainController </p>
  
  <pre><code>package com.controller;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.validation.*;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.view.RedirectView;
  import org.springframework.ui.Model;
  import org.springframework.ui.ModelMap;
  
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import com.security.UrlAuthenticationSuccessHandler;
  import org.apache.log4j.Logger;
  /*
   * author: Crunchify.com
   *
   */
  
  @Controller
  public class MainController {
  
      static Logger log = Logger.getLogger(MainController.class.getName());
  
      @RequestMapping("/showMessage")
      public ModelAndView helloWorld() {
  
          System.out.println("inisde showmessage method");
          log.info("inisde showmessage method");
  
          String message = "&lt;br&gt;&lt;div style='text-align:center;'&gt;"
                  + "&lt;h3&gt;********** Welcome to LDO Support Landing page **********&lt;h3&gt; &lt;/div&gt;&lt;br&gt;&lt;br&gt;";
          return new ModelAndView("showMessage", "message", message);
      }
  
  
      @RequestMapping(value = "/L1SrcLinkPage")
      public String srcLinkMethod(HttpSession session) {
  
          log.info("inside srcLinkMethod method");
          // session.invalidate();
          return "L1SrcLinkPage";
  
      }
  
      @RequestMapping(value = "/L1OutputDisplayPage")
      public String srcOutputDisplayMethod(HttpSession session) {
  
          log.info("inside L1OutputDisplayPage method");
          // session.invalidate();
          return "L1OutputDisplayPage";
  
      }
  
  
      @RequestMapping(value = "/gcmmLink1", method = RequestMethod.GET)
      public ModelAndView gcmmLink1(Model model, HttpServletResponse response) {
  
      log.info("inisde gcmmLink1 method");
          String message = "&lt;br&gt;&lt;div style='text-align:center;'&gt;"
                  + "&lt;h3&gt;********** Showing the output of gcmmLink1 **********&lt;h3&gt; &lt;/div&gt;&lt;br&gt;&lt;br&gt;";
          return new ModelAndView("L1OutputDisplayPage", "message", message);
  
  
      }
  
      @RequestMapping(value = "/gcmmLink2", method = RequestMethod.GET)
      public ModelAndView gcmmLink2() {
  
          log.info("inisde gcmmLink2 method");
          String message = "&lt;br&gt;&lt;div style='text-align:center;'&gt;"
                  + "&lt;h3&gt;********** Showing the output of gcmmLink2 **********&lt;h3&gt; &lt;/div&gt;&lt;br&gt;&lt;br&gt;";
          return new ModelAndView("L1OutputDisplayPage", "message", message);
      }
  }
  </code></pre>
  
  <p>L1SrcLinkPage.jsp</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  
      &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
      &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  
  
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Welcome&lt;/title&gt;
      &lt;/head&gt;
  
  &lt;body&gt;
      &lt;c:url value="/gcmmLink1" var="messageUrl1" /&gt;
      &lt;a href="${messageUrl1}" &gt;GCMM process check!!&lt;/a&gt; &lt;br&gt;
  
      &lt;c:url value="/gcmmLink2" var="messageUrl2" /&gt;
      &lt;a href="${messageUrl2}"&gt;GCMM second process check!!&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>L1OutputDisplayPage.jsp</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Welcome&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h2&gt;${message}&lt;/h2&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h2>solution:</h2>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  function doSomething(UrlValue){
      var ifrm = parent.document.getElementById('displayContent');
      var doc = ifrm.contentDocument? ifrm.contentDocument: ifrm.contentWindow.document;
      alert (doc.getElementById("h1").innerHTML);
      doc.getElementById("h1").innerHTML = "hello, changing the value";
      var urlString = "/LDODashBoard/L1OutputDisplayPage?" + UrlValue + "=true";
      alert (urlString);
      ifrm.contentWindow.location.href = urlString;
  }
  &lt;/script&gt;
  
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Welcome&lt;/title&gt;
  
  
  
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;c:url value="/L1OutputDisplayPage?gcmmLink1=true" var="messageUrl1" /&gt;
      &lt;a href="${messageUrl1}" onClick="doSomething('gcmmLink1');return false;"&gt;GCMM process check!!&lt;/a&gt; &lt;br&gt;
  
      &lt;c:url value="/L1OutputDisplayPage?gcmmLink2=true" var="messageUrl2" /&gt;
      &lt;a href="${messageUrl2}" onClick="doSomething('gcmmLink2');return false;"&gt; GCMM second process check!!&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>