zoukankan      html  css  js  c++  java
  • server服务器信息页面添加步骤

    1. 在数据库更新链接 /portal/server/getServerList

    2. 写实体类 Server.java

    3. 写Server.hbm.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    
    <hibernate-mapping package="com.web.controller.entity">
    	<class name="com.web.controller.entity.Server" table="tsdr_server">
    		<id name="id">
    			<generator class="native"></generator>
    		</id>
    		<property name="ip" />
    		<property name="name" />
    		<property name="useFor" />		
    		<property name="cpuCount" />
    		<property name="cpuNumber" />		
    		<property name="memCount" />
    		<property name="memSize" />		
    		<property name="hddCount" />
    		<property name="hddType" />
    		<property name="hddSize" />		
    		<property name="osVersion" />
    		<property name="manager" />					
    	</class>
    </hibernate-mapping>
    

    4. hibernate.cfg.xml添加上面的xml

    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    
    <hibernate-configuration>
    	<session-factory>
    		<mapping resource ="com/web/controller/entity/User.hbm.xml" />
    		<mapping resource ="com/web/controller/entity/Role.hbm.xml" />
    		<mapping resource ="com/web/controller/entity/Privilege.hbm.xml" />
    		<mapping resource ="com/web/controller/entity/Education.hbm.xml" />
    		<mapping resource ="com/web/controller/entity/Trip.hbm.xml" />
    		<mapping resource ="com/web/controller/entity/Server.hbm.xml" />
    	</session-factory>
    </hibernate-configuration>
    

    5. 写service接口和实现类 (别忘了实现类加@Service)

    6. 重启tomcat, 验证是否正确生成数据库表

    7. 写controller

    package com.web.controller;
    
    import java.util.List;
    
    import javax.annotation.Resource;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import com.web.controller.entity.Server;
    import com.web.controller.service.ServerService;
    
    @Controller
    @RequestMapping("/server")
    public class serverController {
    	@Resource
    	private ServerService serverService;
    	
    	@RequestMapping("/getServerList")
    	public String getEduList(HttpServletRequest request,HttpServletResponse response){		
    		return "/serverController/serverManager"; 
    	}
    	
    	@RequestMapping(value="/getAllServer",produces="application/json;charset=UTF-8")
    	@ResponseBody
    	public List<Server> getAllServer(HttpServletRequest request,HttpServletResponse response){
    		List<Server> serverList = serverService.findAll();			
    		return serverList; 
    	}
    }
    

     8. 写前台 jsp文件

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
    <%--<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
    <%@ taglib uri="myjstl" prefix="c"%>
    
    
    
    <!DOCTYPE html>
    <html>
     	<head>
       		<title>Server Info.</title>
      		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"></script>
         	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/style/mainpagestyle.css" />
    	    <style> 
    		    hr{
    		    	position:relative;
    				top: 500px;
    		    }
    		    a{
    				TEXT-DECORATION:none
    			}
    	    	#footer{
    	    		 position:absolute;
    	    		 bottom: 50px;
    	    		 margin-left :800px;
    	    	}
    	    	.current-page  {
    	    		font-size:12px;
    	 			font-color: #004779;
    	    	}
    	    	.page-num  {
    	    		font-size:12px;
    	 			font-color: #004779;
    	    	}
    	    	input[type=text]::-ms-clear{
    				display: none;
    				
    			}
    			input::-webkit-search-cancel-button{
    				display: none;
    			}  
    			input.t {
    				border:1px solid #fff;
    				background:#fff; 			
    	 			padding-left:5px; 
    	 			height:30px; 
    	 			line-height:30px;
    	 			/*font-size:16px;*/
    	 			/*font-color: #004779;*/
    	 			
    	 		} 
    			input.s {
    				border:1px solid #369;
    				background:#fff; 
    				padding-left:5px;
    		 		height:30px; 
    		 		line-height:30px
    	 		} 
    	 		#MainArea form{
    				padding-left: 0px;
    			}
    			
    			.test_box {
    					     280px; 
    					    min-height: 20px; 
    					    max-height: 300px;
    					    
    					    margin-left: auto; 
    					    margin-right: auto; 
    					    padding: 3px; 
    					    outline: 0; 
    					    border: 0px solid #a0b3d6; 
    					    font-size: 12px; 
    					    word-wrap: break-word;
    					    overflow-x: hidden;
    					    overflow-y: hidden;
    					    _overflow-y: visible;
    			}
    			
    			
    			.textPlace{ position:relative; top:-5px; /*left:5px; right:5px;bottom:5px*/} 
    		</style>
    			
    		<style type="text/css">
    			ul,li{
    				margin:0;
    				padding:0;
    				list-style:none;
    			}
    			#navtop{
    				100%;
    				height:46px;
    				background-color:#ecf0f1;
    				text-align:center;
    				overflow:hidden;
    			}
    			.navtop-skin{
    				float:left;
    				/*position:relative;
    				left:5%;*/
    			}
    			.navtop-skin li{
    				float:left;
    				margin:0px;
    				padding:0 20px;
    				/*position:relative;
    				right:20%;*/
    				line-height:40px;
    				border:solid 0px #000;
    			}	
    		</style>			
    			
    		  <script type="text/javascript">
    		   function load(pn,serverFlag){	
    			   $.getJSON("/portal/server/getAllServer?rn="+Math.random(),function(data){		
    				       var totalCount = data.length; // 总记录数  				    
    			           var pageSize = 20; // 每页显示几条记录  
    			           var pageTotal = Math.ceil(totalCount / pageSize); // 总页数  
    			           var startPage = pageSize * (pn - 1);  
    			           var endPage = startPage + pageSize - 1;  
    			   
    					   var str="";
    					   str+="<tr bgcolor='#d2e9ff' bordercolor='#DEDEDE' >";
    					  
    		        	   str+="<td align='center' width='110px'  rowspan='2'><font style='font-weight:bold;'>IP</font></td>";
    		        	   str+="<td align='center' width='180px'  rowspan='2'><font style='font-weight:bold;'>Server Name</font></td>";
    		        	   str+="<td align='center' width='180px'  rowspan='2'><font style='font-weight:bold;'>Server Usage</font></td>";
    		        	  
    		        	   str+="<td align='center'  height='25px' colspan='2'><font style='font-weight:bold;'>CPU</font></td>";
    		        	   str+="<td align='center'  height='25px'  colspan='2'><font style='font-weight:bold;'>Memory</font></td>";
    		        	   str+="<td align='center'  height='25px'  colspan='3'><font style='font-weight:bold;'>HDD</font></td>";
    		        	   
    		        	   str+="<td align='center' width='200px'   rowspan='2'><font style='font-weight:bold;'>OS Version</font></td>";
    		        	   str+="<td align='center' width='80px'   rowspan='2'><font style='font-weight:bold;'>Manager</font></td>";
    		        	   str+="</tr>";
    		        	   str+="<tr bgcolor='#d2e9ff' bordercolor='#DEDEDE' align='CENTER' valign='MIDDLE' >";
    		        	   str+="<td align='center' width='70px'  height='25px'><font style='font-weight:bold;'>Count</font></td>";
    		        	   str+="<td align='center' width='80px' height='25px'><font style='font-weight:bold;'>Core Num.</font></td>";
    		        	   
    		        	   str+="<td align='center' width='70px'  height='25px'><font style='font-weight:bold;'>Count</font></td>";
    		        	   str+="<td align='center' width='70px' height='25px'><font style='font-weight:bold;'>Size (GB)</font></td>";
    		        	   
    		        	   str+="<td align='center' width='70px'  height='25px'><font style='font-weight:bold;'>Count</font></td>";
    		        	   str+="<td align='center' width='180px' height='25px'><font style='font-weight:bold;'>Type</font></td>";
    		        	   str+="<td align='center' width='80px' height='25px'><font style='font-weight:bold;'>Size (TB)</font></td>";
    		        	   
    		        	
    		        	   str+="</tr>";        	   
    		        	  
    		        	   $(".page-num").text(data.length); 		        	   
    		        	  // alert(pageTotal);
    		        	  if(pageTotal==1){
    		        		  $("#next").disabled=true;
    		        		  $("#prev").disabled=true;
    						 $.each(data,function(i){					 
    							//for(var i = 0;i<data.length;i++){							  
    							   str+="";
    							   str+="<tr bordercolor='#DEDEDE' bgcolor='#ffffff' >";
    							   str+="<input type='hidden' name='id' value=id>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' height='29px' style='font-size:12px;'>"+"  "+data[i].ip+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].name+"</td>";	
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].useFor+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].cpuCount+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].cpuNumber+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].memCount+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].memSize+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].hddCount+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].hddType+"</td>"; 
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].hddSize+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].osVersion+"</td>";
    						  	   str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[i].manager+"</td>";						 
    						  	   str+="</tr>";
    						   });
    					 }  //只有一页
    					 
    					 else{
    						 for (var j = startPage, k = 0; j < endPage, k < pageSize; j++, k++) {  
    				                if( j == totalCount){  
    				                    break;       // 当遍历到最后一条记录时,跳出循环  
    				                }
    				               
    				                str+="";
    								str+="<tr bordercolor='#DEDEDE' bgcolor='#ffffff'>";
    								str+="<input type='hidden' name='id' value=id>";
    								str+="<td align='center'  bordercolor='#DEDEDE'>"+data[j].ip+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' height='29px' style='font-size:12px;'>"+data[j].name+"</td>";	
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].useFor+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].cpuCount+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].cpuNumber+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].memCount+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].memSize+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].hddCount+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].hddType+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].hddSize+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].osVersion+"</td>";
    							  	str+="<td align='center' bordercolor='#DEDEDE' style='font-size:12px;'>"+data[j].manager+"</td>";		
    							  	str+="</tr>";
    				                
    						 }//for
    					 }//else 
    					 $("#tableServer").empty();
    					 $("#tableServer").append(str);
    					 $(".page-num").text(pageTotal); 
    		 		});
    		   }
    			   
    		   function gotoPage(pn,serverFlag) {  				  
    			    $(".current-page").text(pn);  
    			    load(pn,serverFlag);  
    			}     
    		   function getPage(serverFlag) {  			  
    			   var pageTotal=1; // 总页数  
    			   var pn=1;
    			   var totalCount=1;// 总记录数  
    			   var pageSize = 20;// 每页显示几条记录  
    			 
    				 
    			   $.getJSON("/portal/server/getAllServer?rn="+Math.random(),function(data){				   
    			                totalCount = data.length; 
    			                pageSize = 12; 
    			                pageTotal = Math.ceil(totalCount / pageSize); 
    			                var str = pn+"--"+pageTotal;		                
    			       		 
    			                $("#next").click(function() { 
    			                	pn=1; 
    			                	 if (pn == pageTotal) {  
    			                                //alert("后面没有了"); 
    			                                $("#next").disabled=true;
    			                                pn = pageTotal;  
    			                            } else {  
    			                                pn++;  
    			                                gotoPage(pn,serverFlag);  
    			                            }  
    			                        });  
    			                $("#prev").click(function() { 
    			                	// pn=pageTotal; 
    			               
    			                	    if (pn == 1) {  
    			                                //alert("前面没有了");
    			                                $("#prev").disabled=true;
    			                                pn = 1;  
    			                            } else {  
    			                                pn--;  
    			                                gotoPage(pn,serverFlag);  
    			                            }  
    			                        })  
    			                $("#firstPage").click(function() {  
    			                            pn = 1;  
    			                            gotoPage(pn,serverFlag);  
    			                        });  
    			                $("#lastPage").click(function() {  
    			                            pn = pageTotal;  
    			                            gotoPage(pn,serverFlag);  
    			                        });  			              
    			                $("#firstPage").trigger("click");  
    			                  
    			            })  
    			}  			   
    
    	  		function goto(){
    				getPage(${usersession.hasPrivilegeByName('Server Info.')});
    	  		}	  		
    		</script>
      		
      			
    
      	</head> 
    	
      	<body onload="goto()">  
      
    	  	<div id="navtop">
    			<ul class="navtop-skin">
    				<li style="padding-left:20">
    						 
    						<font color="#2c3e50"><strong>| Server Info.|</strong></font>    
    		        </li>
    		    </ul>
    		</div>
    		<br/>
    
    		<center>
    		  	<form action="">
    		    		<table id = "tableServer"  bgColor='#FFFAF0' cellspacing='0px' border='2px'  cellpadding='0px'   style=' border-collapse:collapse'></table>
    			</form>
    			
    			<div id="footer">
    			
    						<a id="firstPage"   href="javascript:void(0);" style="text-decoration:none;"> << </a> 
    						<a id="prev" href="javascript:void(0);" style="text-decoration:none;"> < </a> 
    							<span class="current-page"></span> / <span class="page-num"   ></span>  
    						 
    						<a id="next" href="javascript:void(0);" style="text-decoration:none;"> > </a> 
    						<a id="lastPage" href="javascript:void(0);" style="text-decoration:none;"> >> </a>
    						
    					
    			</div>
    			<br/><br/><br/> 
    		</center> 
      </body>
    </html>
    
  • 相关阅读:
    更换glibc版本进行调试
    HDCTF 2020 Writeup
    Srop 原理与利用方法
    form使用DELETE被转换为GET的原因
    sqlite将时间转换为本地时间读取
    firewall-cmd命令
    windows创建系统服务命令
    Open_vSwitch操作
    Dublin Core
    CWM(Common warehouse metamodel)
  • 原文地址:https://www.cnblogs.com/wujixing/p/5884855.html
Copyright © 2011-2022 走看看