JSP頁面中iframe用法樣本:
首先,在JSP頁面中要包含另一頁面的位置添加如下代碼:
<tr widht="100%" bgcolor="#426199" class="text-01">
<td bgcolor="#FBFBEE" width="100%">
<iframe id="showfrm" name="showfrm" src="" width="100%" height="260" border=0 frameborder=auto marginheight=0 scrolling="auto"></iframe>
</td>
</tr>
然後再JavaScript中增加函數,如:
function shezhi(detail_code,detail_name,detail_fenzhi){
showfrm.location.href = "<%=contextpath%>/servlet/KhpjDetailSetServlet?flag=showfpl&detail_code=" + detail_code+"&detail_name="+detail_name+"&detail_fenzhi="+detail_fenzhi;
}
其次在KhpjDetailSetServlet中增加如下代碼:
if(flag.equals("showfpl"))
{
String detail_code = request.getParameter("detail_code");
String detail_name = request.getParameter("detail_name");
String detail_fenzhi = request.getParameter("detail_fenzhi");
List list_shezhi = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sql ="SELECT B.CODE_NAME,A.FZ_TYPE,A.ZB_FZ FROM T_C_M_ZHZB_DETAIL A LEFT JOIN T_B_C_CODE_DIRECTORY B ON A.ZB_CODE=B.BASE_CODE WHERE A.ZB_CODE='"+detail_code+"'";
try {
conn = DBUtil.getConnection();
if(conn==null)
throw new SQLException("資料庫忙,串連出錯,請重新串連!");
stmt = conn.createStatement();
rs=stmt.executeQuery(sql);
while(rs.next())
{
DetailShezhiVo dshezhi = new DetailShezhiVo();
dshezhi.setDetail_name(rs.getString(1));
dshezhi.setFz_type(rs.getString(2));
dshezhi.setFz_shezhi(rs.getString(3));
list_shezhi.add(dshezhi);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("detail_name", detail_name);
request.setAttribute("detail_fenzhi", detail_fenzhi);
request.setAttribute("list_shezhi", list_shezhi);
dist="/pptf/khpj/KhpjDetailShezhi.jsp"; //String dist 是一個控制頁面跳轉路徑的字串
}
System.out.println("--------1---------");
list_zhzb = query_zhzb();
System.out.println("--------2---------");
request.setAttribute("list_zhzb", list_zhzb);
request.setAttribute("zhzb", zhzb);
request.setAttribute("list_detail", list_detail);
forward(request, response, dist); //跳轉方式是公司內部包中寫的方式
}