控制器将内容或msg变量写入特定的iframe

时间:2015-08-06 03:40:32

标签: spring

我正在使用一个JSP页面,其中有两个iframe,左侧窗格中的一个iframe显示链接&if和右侧窗格中的iframe是显示窗口,当我点击左侧iframe中的链接时,调用控制器,在右窗格/ iframe中显示内容,但它始终在同一窗格/左窗格/左iframe本身显示内容,如何在右侧iframe /显示窗口中显示内容。

参考图片了解更多详情 enter image description here

showMessage

<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<html>
<head>

<link rel="stylesheet" type="text/css"
    href="/LDODashBoard/css/mystyle.css" />

<title>L1 DashBoard page</title>
</head>

<body>
<iframe id="mainContent" src="/LDODashBoard/L1SrcLinkPage.htm"   height="500" width=20% scrolling="no">Main</iframe>
<iframe id="displayContent"  src="/LDODashBoard/L1OutputDisplayPage.htm" height="500" width=70% scrolling="no">Content</iframe>


    <h2>${message}</h2>
</body>
</html>

MainController

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 = "<br><div style='text-align:center;'>"
                + "<h3>********** Welcome to LDO Support Landing page **********<h3> </div><br><br>";
        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 = "<br><div style='text-align:center;'>"
                + "<h3>********** Showing the output of gcmmLink1 **********<h3> </div><br><br>";
        return new ModelAndView("L1OutputDisplayPage", "message", message);


    }

    @RequestMapping(value = "/gcmmLink2", method = RequestMethod.GET)
    public ModelAndView gcmmLink2() {

        log.info("inisde gcmmLink2 method");
        String message = "<br><div style='text-align:center;'>"
                + "<h3>********** Showing the output of gcmmLink2 **********<h3> </div><br><br>";
        return new ModelAndView("L1OutputDisplayPage", "message", message);
    }
}

L1SrcLinkPage.jsp

    <!DOCTYPE html>

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


    <html>
    <head>
    <meta charset="utf-8">
    <title>Welcome</title>
    </head>

<body>
    <c:url value="/gcmmLink1" var="messageUrl1" />
    <a href="${messageUrl1}" >GCMM process check!!</a> <br>

    <c:url value="/gcmmLink2" var="messageUrl2" />
    <a href="${messageUrl2}">GCMM second process check!!</a>
</body>
</html>

L1OutputDisplayPage.jsp

<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<html>
<head>
<meta charset="utf-8">
<title>Welcome</title>
</head>

<body>
<h2>${message}</h2>
</body>
</html>

溶液:

<!DOCTYPE html>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<html>
<head>
<script type="text/javascript">
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;
}
</script>

<meta charset="utf-8">
<title>Welcome</title>



</head>

<body>
    <c:url value="/L1OutputDisplayPage?gcmmLink1=true" var="messageUrl1" />
    <a href="${messageUrl1}" onClick="doSomething('gcmmLink1');return false;">GCMM process check!!</a> <br>

    <c:url value="/L1OutputDisplayPage?gcmmLink2=true" var="messageUrl2" />
    <a href="${messageUrl2}" onClick="doSomething('gcmmLink2');return false;"> GCMM second process check!!</a>
</body>
</html>

0 个答案:

没有答案