Spring MVC - Serving Content Twice

后端 未结 1 1330
清酒与你
清酒与你 2021-01-28 16:10

I\'ve been looking for a week for some guidance on how to server content to my webpage ***twice because severing content once works, with Model or ModelAndView but if a user int

相关标签:
1条回答
  • 2021-01-28 16:57

    So I had to make a new JSP and use an iframe... idea inspired by spotify web player lol ;)

    Here is how I used an Iframe

    <iframe src="wideSidebar" id = "wide-sidebar"></iframe> 
    <script>
        $(document).ready(function() {
            $('.result-div').click(function() {
                $(this).fadeOut(1000).fadeIn(200);
                var text1 = $(this).parent().text().split(":")[1].split("\n")[1];
                $("#wide-sidebar").attr("src", "wideSidebar?id="+text1);
                $("#wide-sidebar").css("display", "block");
            });
        });
    </script>
    @RequestMapping(value = "wideSidebar", method = RequestMethod.GET)
        public ModelAndView getSideBar(@RequestParam(value = "id", required = false) String name) {
            ModelAndView map = new ModelAndView("wideSidebar");
            if (name != null) {
                String offenderID = name.trim();
                System.out.println("requested more info for: " + offenderID);
                Offender offender = null;
                ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
                OffenderDAO offenderDAO = (OffenderDAO) context.getBean("offenderDAO");
                try {
                    offender = offenderDAO.findOffenderById(offenderID);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                ((ConfigurableApplicationContext) context).close();
                map.addObject("selected", offender);
            }
            return map;
        }
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    </head>
    <body>
    First Name: <c:out value="${selected.firstName}"/>
                <div id="vehicles-sidebar">
                    <h1>Vehicles Registered:</h1>
                    <ul>
                        <c:forEach  items="${selected.currentVehicles}" var="vehicle">
                            <li>
                            <span><c:out value="${vehicle.plate}"/></span>
                            <span style="margin:10px;"><c:out value="${vehicle.state}"/></span>
                            <span style="margin:10px;"><c:out value="${vehicle.color}"/></span>
                            <span style="margin:10px;"><c:out value="${vehicle.make}"/></span>
                            <span style="margin:10px;"><c:out value="${vehicle.model}"/></span>
                            <span style="margin:10px;"><c:out value="${vehicle.year}"/></span></li>
                        </c:forEach>
                    </ul>
            </div>
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题