jsp:include參數傳送接收與應用

來源:互聯網
上載者:User

 

先看一個簡單的應用,在a.jsp中寫如下代碼

<div>

<jsp:include page="name.jsp" >
<jsp:param name="name" value="xy" />
</jsp:include>

</div>
這就將名為name,值為xy的參數傳送到name.jsp。

 

那麼在name.jsp中接收參數

 
  <%
 String n=request.getParameter("name");
  if(n!= null && !"".equals(n.trim()))
  out.println(n);
  %>

  <div id="showName"><%=url></div>

 

我們來看一個分頁的應用

 

pager.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<%@tagliburi="/struts-tags"
prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>">
  </head>

 <body>
  <%
   String url = request.getParameter("url");
  %>
  <s:if test="#request.yrlyquery==null">
   <s:if test="data.totalPage>1">
    <s:if test="data.totalPage==pageIntNum">
     <a href="<%=url%>?pageNum=1">首頁</a>&nbsp;
     <a href="<%=url%>?pageNum=<s:property value="pageIntNum-1"/>">上一頁</a>&nbsp;
    </s:if>
    <s:elseif test="pageIntNum==1">
     <a href="<%=url%>?pageNum=<s:property value="pageIntNum+1"/>">下一頁</a>
     <a href="<%=url%>?pageNum=<s:property value="data.totalPage"/>">末頁</a>&nbsp;
    </s:elseif>
    <s:else>
     <a href="<%=url%>?pageNum=1">首頁</a>&nbsp;
     <a href="<%=url%>?pageNum=<s:property value="pageIntNum-1"/>">上一頁</a>&nbsp;
     <a href="<%=url%>?pageNum=<s:property value="pageIntNum+1"/>">下一頁</a>&nbsp;
     <a href="<%=url%>?pageNum=<s:property value="data.totalPage"/>">末頁</a>
    </s:else>
   </s:if>
  </s:if>
  <s:else>
   <s:if test="data.totalPage>1">
    <s:if test="data.totalPage==pageIntNum">
     <a href="<%=url%>?queryType=q&pageNum=1">首頁</a>&nbsp;
     <a href="<%=url%>?queryType=q&pageNum=<s:property value="pageIntNum-1"/>">上一頁</a>&nbsp;
    </s:if>
    <s:elseif test="pageIntNum==1">
     <a href="<%=url%>?queryType=q&pageNum=<s:property value="pageIntNum+1"/>">下一頁</a>&nbsp;
     <a href="<%=url%>?queryType=q&pageNum=<s:property value="data.totalPage"/>">末頁</a>
    </s:elseif>
    <s:else>
     <a href="<%=url%>?queryType=q&pageNum=1">首頁</a>&nbsp;
        <a href="<%=url%>?queryType=q&pageNum=<s:property value="pageIntNum-1"/>">上一頁</a>&nbsp;
        <a href="<%=url%>?queryType=q&pageNum=<s:property value="pageIntNum+1"/>">下一頁</a>
        <a href="<%=url%>?queryType=q&pageNum=<s:property value="data.totalPage"/>">末頁</a>
    </s:else>
   </s:if>
  </s:else>
  當前第
  <s:property value="pageIntNum" />
  頁 共
  <s:property value="data.totalPage" />
  頁
 </body>
</html>


其中pageNum還有data.totalpage等,就涉及到ssh分頁的知識了,就不在這裡贅述了。


stduent.jsp

......

<div>
  <jsp:include page="../pager.jsp">
  <jsp:param  name="url"/ value="stu/Stu_toquery" />
  </jsp:include>
</div>

......

 

這樣就可以完成分頁頁面的嵌入了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.