利用iframe实现提交表单是页面部分刷新

直接上代码:

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%
 3 String path = request.getContextPath();
 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 5 %>
 6 
 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 8 <html>
 9   <head>
10     <base href="<%=basePath%>">
11     
12     
13     <meta http-equiv="pragma" content="no-cache">
14     <meta http-equiv="cache-control" content="no-cache">
15     <meta http-equiv="expires" content="0">    
16     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
17     <meta http-equiv="description" content="This is my page">
18     <!--
19     <link rel="stylesheet" type="text/css" href="styles.css">
20     -->
21 <style type="text/css">
22 .tab_clas{
23     font-size:13px;
24     font-family:"宋体";
25     border-collapse: separate;
26     border-spacing: 0;
27     100%;
28     color:#666666;
29     text-align:center;
30     border-top: 1px solid #c0c0c0;
31     border-right: 1px solid #c0c0c0;
32 }
33 .tab_clas tr td{
34 height:30px;
35     border-left: 1px solid #c0c0c0;
36     border-bottom: 1px solid #c0c0c0;
37 }
38 
39 </style>
40   </head>
41   
42   <body>
43           <form  action="${pageContext.request.contextPath}/policyCompany/queryWhiteList" target="list" >
44         <table class="tab_clas">
45             <tr>
46                 <td>公司名称</td>
47                 <td><input type="text" name="name"></td>
48                 <td>公司邮箱</td>
49                 <td><input type="text" name="type"></td>
50                 <td>审核状态</td>
51                 <td><input type="text" name="type"></td>
52             </tr>
53             <tr>
54                 <td>创建时间</td>
55                 <td colspan="4"><input type="text"></td>
56                 <td><input type="submit" value="查询" /> </td>
57             </tr>
58         </table>
59         </form>
60         <iframe name="list" src="${pageContext.request.contextPath}/policyCompany/queryWhiteList" width="100%" height="100%"></iframe>
61   </body>
62 </html>

iframe中是查询出的结果列表。iframe中src是在页面初始化时要展示的连接。当上面的form提交之后,会自动变化。所以src可以为空

需要注意的是  form中的 target属性必须要和iframe中的name属性相同

原文地址:https://www.cnblogs.com/andong2015/p/4415453.html