html_checkbox示例
来源:互联网 发布:医药政策法规数据库 编辑:程序博客网 时间:2024/06/06 21:40
package com.qingyuan.httpclient;public class AllServerInfo{ private String ip; private String port; private String contextPath; private String clusterName; private String serverType; private String lastActivityTime; private String activity; private String description; public String getIp() { return ip; } public void setIp(String ip) { this.ip = ip; } public String getPort() { return port; } public void setPort(String port) { this.port = port; } public String getContextPath() { return contextPath; } public void setContextPath(String contextPath) { this.contextPath = contextPath; } public String getClusterName() { return clusterName; } public void setClusterName(String clusterName) { this.clusterName = clusterName; } public String getServerType() { return serverType; } public void setServerType(String serverType) { this.serverType = serverType; } public String getLastActivityTime() { return lastActivityTime; } public void setLastActivityTime(String lastActivityTime) { this.lastActivityTime = lastActivityTime; } public String getActivity() { return activity; } public void setActivity(String activity) { this.activity = activity; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public AllServerInfo() { } public AllServerInfo(String ip, String port, String contextPath, String clusterName, String serverType, String lastActivityTime, String activity, String description) { super(); this.ip = ip; this.port = port; this.contextPath = contextPath; this.clusterName = clusterName; this.serverType = serverType; this.lastActivityTime = lastActivityTime; this.activity = activity; this.description = description; } public String toString() { return ""; }}package com.qingyuan.httpclient;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class ServerInfoServlet extends HttpServlet{ /** serialVersionUID */ private static final long serialVersionUID = -8367229371456636932L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=gbk"); PrintWriter out = response.getWriter(); List<AllServerInfo> arrayList = new ArrayList<AllServerInfo>(); AllServerInfo server = new AllServerInfo("25.111.108.133","8080","ddc","ddc","timer","2015-01-04","active",""); AllServerInfo server2 = new AllServerInfo("25.111.108.197","8080","ddc","ddc","json","2015-01-04","inactive",""); AllServerInfo server3 = new AllServerInfo("25.111.108.112","8080","ddc","ddc","ajax","2015-01-04","inactive",""); AllServerInfo server4 = new AllServerInfo("25.111.108.113","8080","ddc","ddc","ajax","2015-01-04","inactive",""); AllServerInfo server5 = new AllServerInfo("25.111.108.114","8080","ddc","ddc","json","2015-01-04","inactive",""); AllServerInfo server6 = new AllServerInfo("25.111.108.115","8080","ddc","ddc","ajax","2015-01-04","inactive",""); arrayList.add(server);arrayList.add(server2);arrayList.add(server3); arrayList.add(server4);arrayList.add(server5);arrayList.add(server6); request.setAttribute("allserver", arrayList); RequestDispatcher dispatcher = request.getRequestDispatcher("/server.jsp"); dispatcher .forward(request, response); } }
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ page import="com.qingyuan.httpclient.AllServerInfo"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <script type="text/javascript"> function selectServer(){var server = new Object();var ipStr ="";var inputs = document.getElementsByTagName("input");for(var i=0;i<inputs.length;i++){ var obj = inputs[i]; if (obj.type == 'checkbox' && obj.checked&&obj.ip != null && obj.ip !="") { var port ="8080"; if(obj.port != null && obj.port != "") { port = obj.port; } ipStr =ipStr+obj.ip+","+port+";"; }} alert(ipStr); if(ipStr!=null && ipStr!=""){ipStr = ipStr.substr(ipStr,ipStr.length-1);}else{alert("choose server!");return false;}server.ipStr = ipStr;window.returnValue = server; window.close();} function checkServer(ServerType, obj) { var check = obj.checked; var inputs = document.getElementsByTagName("input"); var serverTypes = document.getElementsByName(ServerType); for (var i = 0; i < inputs.length; i++) { serverTypes[i].checked = check; // 获取Dom对象的自定义属性 alert(serverTypes[i].ip + ":" + serverTypes[i].port); } } function checkAllServer(inputObj) { var check = inputObj.checked; var inputs = document.getElementsByTagName("input"); for (var i = 0; i < inputs.length; i++) { var obj = inputs[i]; if (obj.type == 'checkbox') { obj.checked = check; } } } </script> </head> <body> <table id="serverList" style="display: block;align: center cellspacing="0" cellpadding="0" width="98%" align="center" border="0""> <tr> <td> <input id="checkAllserverBox" type="checkbox" onclick="javascript:checkAllServer(this);"> </td> <td>ip address</td><td>port</td><td>context</td> <td>clustername</td><td>servertype</td><td>lastacitvetime</td> <td>active</td><td>description</td> </tr> <% Map<String,Integer> map = new HashMap<String,Integer>(); List<AllServerInfo> remoteServers = (List<AllServerInfo>)request.getAttribute("allserver"); for (int i =0; i < remoteServers.size(); i++) { %> <tr> <!-- 展示行的第一列 begin --> <td><input id="serverType" type="checkbox" ip ="<%=remoteServers.get(i).getIp()%>" port="<%=remoteServers.get(i).getPort()%>" name="<%=remoteServers.get(i).getServerType()%>"></td> <!-- 展示行的第一列 end --> <td><%=remoteServers.get(i).getIp()%></td><td><%=remoteServers.get(i).getPort()%></td><td><%=remoteServers.get(i).getContextPath()%></td><td><%=remoteServers.get(i).getClusterName()%></td> <td> <% String serverType = remoteServers.get(i).getServerType(); if (serverType == null) { serverType = " "; } Integer num = map.get(serverType); if(num == null) { num = 1; } else { num = num +1; } map.put(serverType,num); out.print(serverType); %> </td> <td><%=remoteServers.get(i).getLastActivityTime()%></td> <td><%=remoteServers.get(i).getActivity()%></td> <td><%=remoteServers.get(i).getDescription()%></td> </tr> <% } %> <tr><td colspan="10" align="right">totalrecords: <font color="green"><%=remoteServers.size()%></font><% for(Map.Entry entry : map.entrySet()) { %> <%=entry.getKey()%>: <font color="green"><%= entry.getValue()%></font> <% } %></td> </tr> </table> <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="500px">servertype:<%for(Map.Entry entry : map.entrySet()){ %> <input id="checkServerCheckBox" type="checkbox" name="<%=entry.getKey() %>" width="20px" onclick="checkServer('<%=entry.getKey() %>',this)"><%= entry.getKey()%> <% }%></td></tr><tr height="25"><td align="center"><input type="button" name="confirm" value="submit" onclick="selectServer()" /><input type="button" name="close" value="cancel" onclick="window.close()" /></td></tr></table> </body></html>
------------------------------------------------------------------------------------------------------------杂碎:<[不相干的东西]>// 自定义html标签中的属性:<input type="checkbox" name="<%=csdnServers.get(i).getServerType()%>" ip="<%=csdnServers.get(i).getIp() %>" port="<%=csdnServers.get(i).getPort()%>"/><input id="checkbox" type="checkbox" name="<%=entry.getKey() %>" width="20px" onclick="checkServer('<%=entry.getKey() %>',this)"><%= entry.getKey()%>;var server = new Object();var ipStr ="";server.ipStr = ipStr;window.returnValue = server;window.close();var orgaArray = new Array();window.onload = initOrgaArray;// http://suo.iteye.com/blog/508572 window.returnValue使用方法returnValue是javascript中html的window对象的属性,目的是返回窗口值,当用window.showModalDialog函数打开一个IE的模式窗口(模式窗口知道吧,就是打开后不能操作父窗口,只能等模式窗口关闭时才能操作)时,用于返回窗口的值,下面举个例子// HTML_INPUT详细属性方法事件介绍http://wenku.baidu.com/link?url=Lu-jj5NGqM0iigcnau6AGShdKjfWqoWFrVfQai026rBrS2bZvzfMn-yfGiprRK5e60dBKaOy3mTifdluvgpaUf8rni_xShcdttJPqgpE9ZS// html <[自定义标记属性]><input type="checkbox" id="" value="" server="" ip="" port="">http://www.360doc.com/content/09/1030/14/426899_8092609.shtml// Map<String,Integer> map = new HashMap<String,Integer>();// Integer num = map.get(serverType);Integer java.util.Map.get(Object key)Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases. More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null.
0 0
- html_checkbox示例
- 示例
- 示例
- 示例
- 示例
- 示例
- Winpcap示例,Libpcap示例
- CMSChart 示例
- DataGrid 示例
- 示例:Radio
- 示例:Calendar
- Sqlldr示例
- 按键示例
- SQL示例
- Singleton示例
- 串口示例
- JLabel示例
- JButton示例
- java5的Semaphere同步工具(十四)
- 棕着住纵佐桌祖遵注装准仔纵诅作拙撞鬃
- stm32---iic通信
- Activiti学习(一)
- [Leetcode]Palindrome Number
- html_checkbox示例
- 使用函数对象代替函数作算法的 参数
- linux环境下的hive mysql hadoop环境搭建
- mongodb monk limit 分页
- Linux内核源码分析--文件系统(二、高速缓存区)
- UnityTestTool实用解释
- 一个完整的以在线重定义方式普通表转分区表的方案
- Windows移动硬盘修复工具C源代码
- Java StringBuffer相关解惑