Click a link in one frame and display a JSP in the other frame

廉价感情. 提交于 2019-12-10 13:36:11

问题


I created two frames which respectively contain two links.

When the first frame gets clicked, I would like to display a JSP page in the second frame.

But I can't get it to work. When the first frame gets clicked, it opens the JSP page in a new window.

I paste some of my code.

This is my main.jsp

<html>

  <frameset cols="50%,50%">
  <frame src="frame1.jsp">
  <frame src="frame2.jsp">
  </frameset>

</html>

frame1.jsp

<html>

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Frame 1 with links</title>
  </head>

  <body>
    <body bgcolor="lightBlue">

      <h2>Java Tutorial</h2>
      <a href="subframe1.jsp" target="frame2.jsp"> tracking system</a>
      <a href="subframe2.jsp" target="frame2.jsp">data information</a>

  </body>

</html>

frame2.jsp

<html>

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  </head>

  <body>
  </body>

</html>

subframe1.jsp

<html>

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
  </head>

  <body>

    <form action="insertData.jsp" action="post" >

      DATA ID:<input type="text" name="data_id"><br>
      East:<input type="text" name="east"><br>
      North:<input type="text" name="north"><br>
      <input type="submit" value="Save">
    </form>

  </body>
</html>

How can I fix that?


回答1:


First I must say - Framesets are bad, if you can avoid using them then do so.

That said, the target value of your links needs to be a framename.

You have not named your frames, you need to specify a name attribute.

So you need to change your frameset to look more like:

<frameset cols="50%,50%">
<frame name="frame1" src="frame1.jsp">
<frame name="frame2" src="frame2.jsp">
</frameset>

and then change your links accordingly:

<a href="subframe1.jsp" target="frame2"> tracking system</a>
<a href="subframe2.jsp" target="frame2">data information</a>


来源:https://stackoverflow.com/questions/21760836/click-a-link-in-one-frame-and-display-a-jsp-in-the-other-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!