代码之家  ›  专栏  ›  技术社区  ›  aeq

div在jsp的新窗口中打开自己?

  •  0
  • aeq  · 技术社区  · 16 年前

    我有一个jsp“模板”视图,其中包括来自其他几个jsp的内容 <div>

    在包含的jsp中,我希望有一个名为“popup”(或其他)的超链接。单击此链接时,此包含的jsp的内容将从模板jsp中“弹出”,并打开到其自己的窗口中。

    例如。:

    模板.jsp:

    <body>
       <div>
          //include jsp-1.jsp
       </div>
       <div>
          //include jsp-2.jsp
       </div>
    </body>
    

    <p>
      ...
      <a href="">Pop out</a> //Clicking this will open a new window
                             //containing only the contents of jsp-1.jsp
    </p>
    
    2 回复  |  直到 16 年前
        1
  •  0
  •   Matt Ball    16 年前

    这不应该太难。我不确定您是否将其设置为让浏览器直接请求JSP文件,但如果是这样的话,类似这样的设置应该对您有用:

    jsp-1.jsp:

    <p>
      ...
      <a href="/jsp-1.jsp" target="_blank">Pop out</a>
    </p>
    

    回复:关于丢失CSS和JS文件的评论,这里是我如何解决这个服务器端问题的。有点难看,但效果很好。

    模板.jsp:

    <html>
    <head>
    ...
    </head>
    <body>
       <c:set var="ContentOnly" value="true" scope="request"/>
       <div>
          <jsp:include page="jsp-1.jsp" />
       </div>
       <div>
          <jsp:include page="jsp-2.jsp" />
       </div>
       <c:remove var="ContentOnly" scope="request"/>
    </body>
    </html>
    

    <c:if test="${(empty ContentOnly) or (not ContentOnly)}">
        <html>
        <head>
        ...
        <!-- jsp-1 required CSS and JS here -->
        <!-- these will only be included when the page is requested as "standalone" -->
        ...
        </head>
        <body>
    </c:if>
        ...
        <!-- jsp-1 content here -->
        ...
    <c:if test="${(empty ContentOnly) or (not ContentOnly)}">
        </body>
        </html>
    </c:if>
    
        2
  •  0
  •   zod    16 年前

    使用javascript窗口.open

    推荐文章