O'Reilly logo

Jakarta Struts Cookbook by Bill Siggelkow

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.17. Using Frames

Problem

You need to reference an Action or JSP page from within one frame to another.

Solution

Use the Struts html:frame tag to create frame elements with the proper URLs for your Struts application, as in Example 3-20 (frame_test.jsp).

Example 3-20. Generating a frame set with Struts

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<frameset cols="50%,*">
  <html:frame frameName="_frame1" 
                   page="/frame1.jsp" 
            marginwidth="10" 
           marginheight="10"
              scrolling="auto" 
            frameborder="1"/>
  <html:frame frameName="_frame2" 
                   page="/frame2.jsp" 
            marginwidth="10" 
           marginheight="10"
              scrolling="auto" 
            frameborder="1"/>
</frameset>

Within the individual frame's source JSP, use the target attribute on the html:link and html:form tags to refer to the other frame. The JSP in Example 3-21 (frame1.jsp) demonstrates this approach.

Example 3-21. Frame with link to other frame

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<html>
<head>
  <title>Struts Cookbook - Chapter 04: Frame Test</title>
</head>
<body bgcolor="white">
<h2>Frame 1</h2>
  <html:link href="frame2.jsp?calledBy=FRAME_1" target="_frame2">
    Call Frame2
  </html:link>
  <p>
  Message received:&nbsp;
  <c:out value="${FrameForm.map.message}"/>
</body>
</html>

Likewise, frame2.jsp shown in Example ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required