jsp页面导入excl文件并将文件内容解析存进数据库,求实例

现在要做一个jsp页面功能按钮导入excl文件,是点击按钮弹出文件选取框的那种!然后将文件接收到后台解析,最后存入数据库

1个回答

用 poi 处理上传的文件

附上链接 http://blog.csdn.net/onepersontz/article/details/49891405

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
怎么用C#读取文本文件,然后写进excl文件?
怎么用C#读取文本文件,然后写进excl文件? 有懂得吗?我是小白 不懂
C#中得winfrom项目,如何导入excl文本,并且可以获取数据的数量,最后可以进行打印或则导出
我要做的是一个摇奖的程序,导入excl文本,并且能获取数据的数据数量,最后导出或则是打印的技术代码,大神们,求助呀!
如何用POI 读取excl模板,然后通过数据库写入大量数据 ,创建多个sheet,求解决!!!
![模板](https://img-ask.csdn.net/upload/201901/28/1548675614_119810.jpg) 根据记录数,自动分工作簿,每个工作簿11条记录
用java实现:上传excl表格。读取数据,输出结果。
package chexianchaxun; import java.io.*; public class FeiYong{ public static void main(String[] args) throws Exception { java.net.URL url = new java.net.URL("http://********"); java.net.URLConnection con = url.openConnection(); con.setUseCaches(false); con.setDoOutput(true); con.setDoInput(true); DataOutputStream dataOut = new DataOutputStream(con.getOutputStream()); //字节流:InputStream(读取)、OutputStream(写入) String Msg = "<Request> <VinNo>ZAMJK39E6B0060491</VinNo><LicenseNo></LicenseNo><LoginID>215288</LoginID></Request>" ; /**转保车辆VinNo为必填 */ System.out.println(Msg); //字符流:Writer(写入)、Reader(读取) dataOut.write(Msg.getBytes("gbk"));//将已经解析出来的字节数据转化为gbk编码格式的字符串 dataOut.flush(); dataOut.close(); InputStream is = con.getInputStream(); InputStreamReader isr = new InputStreamReader(is, "gbk"); BufferedReader br = new BufferedReader(isr); StringBuffer sb = new StringBuffer(); String templine=null; while ((templine = br.readLine()) != null) sb.append(templine); System.out.println(sb.toString()); } } 如上。 当个输入信息车架号,通过接口,可以获取对应的数据信息。 现需要实现,excl表格形式上传,表格内有多条车辆的车架号数据,通过接口,然后再获取对应的数据信息。 感谢Always_MyLoverX 的耐心回答
java poi读取excl,如何放入map
![图片说明](https://img-ask.csdn.net/upload/201606/22/1466595736_474394.png) 如图,这种格式的。java poi读取excl,如何放入map
Linux中用C的msgget()不使用IPC_EXCL也返回EEXIST错误
Linux中用C的msgget()不使用IPC_EXCL也返回EEXIST错误,网上都说不使用IPC_EXCL,光使用IPC_CREAT会返回msgid或创建一个新的队列, 但是,在我的程序里面,并!没!有! 求助大神们帮我看看怎么回事的! 我是在centos6.5中运行的,用的GCC编译 这个是运行的结果: ![图片说明](https://img-ask.csdn.net/upload/201504/13/1428937533_953371.png) 这个是代码: ``` #include <stdio.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <time.h> #include <errno.h> void msg_show_attr(int msg_id, struct msqid_ds msg_info){ int ret = -1; sleep(1); ret = msgctl(msg_id, IPC_STAT, &msg_info); if(ret == -1){ printf("failed to get msg info!\n"); return; } printf("--------now print info:---------\n"); printf("队列中字节数:%ld\n", msg_info.msg_cbytes); printf("队列中消息数:%d\n", (int)msg_info.msg_qnum); printf("队列中最大字节数:%d\n", (int)msg_info.msg_qbytes); printf("最后发送(接收)消息的进程:%d(%d)\n", msg_info.msg_lspid, msg_info.msg_lrpid); printf("最后发送(接收)消息的时间:%s(%s)\n", ctime(&(msg_info.msg_stime)), ctime(&(msg_info.msg_rtime))); printf("最后变化的时间:%s\n", ctime(&(msg_info.msg_ctime))); printf("消息UID=%d, GID=%d\n", msg_info.msg_perm.uid, msg_info.msg_perm.gid); } int main(){ int ret = -1; int msg_flags, msg_id; key_t key; struct msgmbuf{ int mtype; char mtext[10]; }; struct msgmbuf msg_mbuf; struct msqid_ds msg_info; int msg_sflags, msg_rflags; char *msgpath = "/ipc/msg"; //键值构建函数,获取IPC键值。 key = ftok(msgpath, 'c'); if(key == -1){ printf("ftok failed: %d!\n", errno); return -1; } printf("ftok succeed: %d!\n", key); //msgget()用来创建或者获取消息队列, msg_flags = 0; msg_flags |= IPC_CREAT; msg_flags |= IPC_EXCL; msg_id = msgget(key, msg_flags|0x0666); printf("msg flag is %d\nmsgget return: %d\n", msg_flags, msg_id); if(msg_id == -1){ printf("msgget failed: %s!\n", strerror(errno)); return -1; } printf("msgget succeed: %d!\n", msg_id); msg_show_attr(msg_id, msg_info); //开始发送消息 //并且此处设置为了IPC_NOWAIT,因此不会等待消息发送成功!即为异步执行! msg_sflags = IPC_NOWAIT; msg_mbuf.mtype = 10; memcpy(msg_mbuf.mtext, "测试消息", sizeof("测试消息")); ret = msgsnd(msg_id, &msg_mbuf, sizeof("测试消息"), msg_sflags); if(ret == -1){ printf("msgsnd failed!\n"); }else{ printf("msgsnd succeed!\n"); } msg_show_attr(msg_id, msg_info); //开始接收消息 struct msgmbuf msgmbuf_r; msg_rflags = IPC_NOWAIT|MSG_NOERROR; ret = msgrcv(msg_id, &msgmbuf_r, 10, 10, msg_rflags);//成功返回接收的数据长度 if(ret == -1){ printf("msgrcv failed: %d!\n", errno); }else{ printf("msgrcv succeed, msg length: %d.\n", ret); } msg_show_attr(msg_id, msg_info); return 0; } ``` 还有图片版的代码: ![图片说明](https://img-ask.csdn.net/upload/201504/13/1428937808_790296.png)
PHP网站语句如何优化,希望和高手一起探讨下
我的网站是PHP网站,使用的数据库是MySQL 的目前直接用网上的采集插件出现了很多慢查询和扫全表的动作,自己也在对应的表里建立了普通索引,但还是无法得到解决,一直报错在SQL语句里,对于这块本人学习尚浅。 MySQL引擎是InnoDB,下面是索引截图: ![图片说明](https://img-ask.csdn.net/upload/201906/16/1560632068_941383.jpg) 报错语句: select url from ve123_links_temp where url like 'jmw.com.cn%' UPDATE `ve123_links_temp` SET `no_id`='1' WHERE url='http://app.hiapk.com/hiapk/about/agreement' 还请各位高手指点迷津,到底如何优化 语句: <?php //抓全站--- 多线程 function all_links_duo($site_id,$ceng,$include_word,$not_include_word) { global $db; $new_url=array(); $fenge=array(); $nei=1;//1代表只收内链 2代表外链 空代表所有 $numm=2;//开启多少线程 echo "<br><b>开始抓取第".$ceng."层</b><br>"; $ceng++; $row=$db->get_one("select * from ve123_links_temp where site_id='".$site_id."' and no_id='0'"); if(empty($row)){echo " ---------- 没有新链接了<br>";return;}//如果找不到新增加url,则结束 $query=$db->query("select * from ve123_links_temp where site_id='".$site_id."' and no_id='0'"); while($row=$db->fetch_array($query)) { $new_url[]=$row[url]; } $he_num = ceil(count($new_url)/$numm);//计算需要循环多少次 $fenge=array_chunk($new_url,$numm);//把数组分割成多少块数组 每块大小$numm /* echo "一共多少个"; echo count($new_url); echo "需要循环"; echo $he_num; echo "次<br>"; */ for($i=0;$i<=$he_num;$i++) { /*echo "开始循环第 ".$i." 次<br>"; print_r($fenge[$i]); echo "<br>";*/ $fen_url = array(); $fen_url = cmi($fenge[$i]); //需要把得到的数组 (数组只包括 网址和源码) 分析 写入数据库 , /*echo "<b>本次抓完的网址为</b>"; print_r($fen_url[url]); echo "<br>";*/ foreach ((array)$fen_url as $url => $file) { $links = array(); $temp_links = array(); $cha_temp = array(); $loy = array(); $new_links = array(); $cha_links = array(); $cha_links_num = array(); $links = _striplinks($file); //从htmlcode中提取网址 $links = _expandlinks($links, $url); //补全网址 $links=check_wai($links,$nei,$url); $links=array_values(array_unique($links)); $bianma = bianma($file); //获取得到htmlcode的编码 $file = Convert_File($file,$bianma); //转换所有编码为gb2312 $loy = clean_lry($file,$url,"html"); $title=$loy["title"]; //从数组中得到标题,赋值给title $pagesize=number_format(strlen($file)/1024, 0, ".", ""); $fulltxt=Html2Text($loy["fulltext"]); $description=$loy["description"]; //从数组中得到标题,赋值给description $keywords=$loy["keywords"]; //从数组中得到标题,赋值给keywords $lrymd5=md5($fulltxt); $updatetime=time(); if($title==""){$title=str_cut($fulltxt,65); } //根据url,更新内容 $array=array('lrymd5'=>$lrymd5,'title'=>$title,'fulltxt'=>$fulltxt,'description'=>$description,'keywords'=>$keywords,'pagesize'=>$pagesize,'updatetime'=>$updatetime); $db->update("ve123_links",$array,"url='".$url."'"); $all_num = count($links); //开始读取 ve123_links_temp 中所有site_id 为$site_id 的url 然后和抓取的 $links 数组比较,将得到的差集创建到 ve123_links_temp 中 $query=$db->query("select url from ve123_links_temp where url like '%".getdomain($url)."%'"); while($row=$db->fetch_array($query)) { $temp_links[]=rtrim($row[url],"/"); } $cha_temp=array_diff($links,$temp_links); foreach((array)$cha_temp as $value) { if(check_include($value, $include_word, $not_include_word )) { $arral=array('url'=>$value,'site_id'=>$site_id); $db->insert("ve123_links_temp",$arral); } } //开始读取 ve123_links 中所有site_id 为 $site_id 的url 然后和抓取的 $links 数组比较,将得到的差集创建到 ve123_links 中 合集则输出 已存在了 $query=$db->query("select url from ve123_links where url like '%".getdomain($url)."%'"); while($row=$db->fetch_array($query)) { $new_links[]=rtrim($row[url],"/"); } $cha_links=array_diff($links,$new_links); foreach((array)$cha_links as $value) { if(check_include($value, $include_word, $not_include_word )) { $array=array('url'=>$value,'site_id'=>$site_id,'level'=>'1'); $db->insert("ve123_links",$array); $cha_links_num[]=$value; } } $cha_num = count($cha_links_num); printLinksReport($cha_num, $all_num, $cl=0); echo "<a href=".$url." target=_blank>".$url. "</a><br>"; $arral=array('no_id'=>1); $db->update("ve123_links_temp",$arral,"url='$url'"); ob_flush(); flush(); } } all_links_duo($site_id,$ceng,$include_word,$not_include_word);//再次调用本函数开始循环 } //一键找站 function find_sites($site_id,$ceng) { global $db; $new_url=array(); $fenge=array(); $numm=20;//开启多少线程 echo "<br><b>开始抓取第".$ceng."层</b><br>"; $ceng++; $row=$db->get_one("select * from ve123_sites_temp where site_id='".$site_id."' and no_id='0'"); if(empty($row)){echo " ---------- 没有新链接了<br>";return;}//如果找不到新增加url,则结束 $query=$db->query("select * from ve123_sites_temp where site_id='".$site_id."' and no_id='0'"); while($row=$db->fetch_array($query)) { $new_url[]=$row[url]; } $he_num = ceil(count($new_url)/$numm);//计算需要循环多少次 $fenge=array_chunk($new_url,$numm);//把数组分割成多少块数组 每块大小$numm for($i=0;$i<=$he_num;$i++) { $fen_url = array(); $fen_url = cmi($fenge[$i]); //需要把得到的数组 (数组只包括 网址和源码) 分析 写入数据库 , foreach ((array)$fen_url as $url => $file) { $links = array(); $fen_link = array(); $nei_link = array(); $wai_link = array(); $new_temp = array(); $cha_temp = array(); $new_site = array(); $cha_site = array(); $new_lik = array(); $cha_lik = array(); $links = _striplinks($file); //从htmlcode中提取网址 $links = _expandlinks($links, $url); //补全网址 $fen_link=fen_link($links,$url); //把内链和外链分开 $nei_link=array_values(array_unique($fen_link[nei])); //过滤内链 重复的网址 $wai_link=GetSiteUrl($fen_link[wai]); //把外链都转换成首页 $wai_link=array_values(array_unique($wai_link)); //过滤外链 重复的网址 //读出 ve123_sites_temp 中所有 site_id=-1 and no_id=0 $query=$db->query("select url from ve123_sites_temp where site_id='".$site_id."'"); while($row=$db->fetch_array($query)) { $new_temp[]=$row[url]; } $cha_temp=array_diff($nei_link,$new_temp);//与内链进行比较 得出差集 //将差集创建到 ve123_sites_temp 中 foreach((array)$cha_temp as $value) { $arral=array('url'=>$value,'site_id'=>$site_id,'no_id'=>0); $db->insert("ve123_sites_temp",$arral); } //读出 ve123_sites 中所有 site_id=-1 global $db; $query=$db->query("select url from ve123_sites where site_no='".$site_id."'"); while($row=$db->fetch_array($query)) { $new_site[]=$row[url]; } $cha_site=array_diff($wai_link,$new_site);//与外链进行比较 得出差集 //将差集创建到 ve123_sites 中 foreach((array)$cha_site as $value) { $arral=array('url'=>$value,'site_no'=>$site_id); $db->insert("ve123_sites",$arral); } //读出 ve123_links 中所有 site_id=-1 global $db; global $db; $query=$db->query("select url from ve123_links where site_id='".$site_id."'"); while($row=$db->fetch_array($query)) { $new_lik[]=$row[url]; } $cha_lik=array_diff($wai_link,$new_lik);//与外链进行比较 得出差集 //将得到的差集 创建到 ve123_links foreach ((array)$cha_lik as $value) { $array=array('url'=>$value,'site_id'=>$site_id); $db->insert("ve123_links",$array); echo "<font color=#C60A00><b>抓取到:</b></font>"; echo "<a href=".$value." target=_blank>".$value."</a><br>"; } $arral=array('no_id'=>1); $db->update("ve123_sites_temp",$arral,"url='$url'"); ob_flush(); flush(); } } find_sites($site_id,$ceng);//再次调用本函数开始循环 } //一键更新 已抓站 function Update_sites($site_id) { global $db; $numm=20;//开启多少线程 $new_url = array(); $fenge = array(); $query=$db->query("select url from ve123_links where site_id='".$site_id."' and length(lrymd5)!=32"); while($row=$db->fetch_array($query)) { $new_url[]=$row[url]; } $he_num = ceil(count($new_url)/$numm);//计算需要循环多少次 $fenge=array_chunk($new_url,$numm);//把数组分割成多少块数组 每块大小$numm for($i=0;$i<=$he_num;$i++) { $fen_url = array(); $fen_url = cmi($fenge[$i]); //需要把得到的数组 (数组只包括 网址和源码) 分析 写入数据库 , foreach ((array)$fen_url as $url => $file) { $links = array(); $temp_links = array(); $cha_temp = array(); $loy = array(); $new_links = array(); $cha_links = array(); $cha_links_num = array(); $bianma = bianma($file); //获取得到htmlcode的编码 $file = Convert_File($file,$bianma); //转换所有编码为gb2312 if($file==-1) {echo "<b><font color=#C60A00>抓取失败</b></font> ".$url."<br>"; continue;} $loy = clean_lry($file,$url,"html"); //设置分析数组 $title=$loy["title"]; //从数组中得到标题,赋值给title $pagesize=number_format(strlen($file)/1024, 0, ".", ""); $fulltxt=Html2Text($loy["fulltext"]); $description=$loy["description"]; //从数组中得到标题,赋值给description $keywords=$loy["keywords"]; //从数组中得到标题,赋值给keywords $lrymd5=md5($fulltxt); $updatetime=time(); if($title==""){$title=str_cut($fulltxt,65); } //根据url,更新内容 echo "<b><font color=#0Ae600>已更新</font></b>"; echo $title; echo "<a href=".$url." target=_blank>".$url. "</a><br>"; $array=array('lrymd5'=>$lrymd5,'title'=>$title,'fulltxt'=>$fulltxt,'description'=>$description,'keywords'=>$keywords,'pagesize'=>$pagesize,'updatetime'=>$updatetime); $db->update("ve123_links",$array,"url='".$url."'"); } } } //一键找站 暂时不用的 function find_sites_($url) { $oldtime=time(); $site_id = -1; $numm=10; $links=array(); $fen_link=array(); $lrp =array(); $nei_link =array(); $wai_link =array(); $new_temp =array(); $cha_temp =array(); $new_site =array(); $cha_site =array(); $new_lik =array(); $cha_lik =array(); $fenge =array(); $lrp = cmi($url); $links = _striplinks($lrp[$url]); //从htmlcode中提取网址 $links = _expandlinks($links, $url); //补全网址 $fen_link=fen_link($links,$url); //把内链和外链分开 $nei_link=array_values(array_unique($fen_link[nei])); //过滤内链 重复的网址 $wai_link=GetSiteUrl($fen_link[wai]); //把外链都转换成首页 $wai_link=array_values(array_unique($wai_link)); //过滤外链 重复的网址 /*print_r($nei_link); echo "<br><br>"; print_r($wai_link);*/ //读出 ve123_sites_temp 中所有 site_id=-1 and no_id=0 global $db; $query=$db->query("select url from ve123_sites_temp where site_id='-1' and no_id='0'"); while($row=$db->fetch_array($query)) { $new_temp[]=$row[url]; } $cha_temp=array_diff($nei_link,$new_temp);//与内链进行比较 得出差集 //将差集创建到 ve123_sites_temp 中 foreach((array)$cha_temp as $value) { $arral=array('url'=>$value,'site_id'=>$site_id,'no_id'=>0); $db->insert("ve123_sites_temp",$arral); } //读出 ve123_temp 中所有 site_id=-1 global $db; global $db; $query=$db->query("select url from ve123_sites where site_no='-1'"); while($row=$db->fetch_array($query)) { $new_site[]=$row[url]; } $cha_site=array_diff($wai_link,$new_site);//与外链进行比较 得出差集 //将差集创建到 ve123_sites 中 foreach((array)$cha_site as $value) { $arral=array('url'=>$value,'site_no'=>$site_id); $db->insert("ve123_sites",$arral); } //读出 ve123_links 中所有 site_id=-1 global $db; global $db; $query=$db->query("select url from ve123_sites where site_id='-1'"); while($row=$db->fetch_array($query)) { $new_lik[]=$row[url]; } $cha_lik=array_diff($wai_link,$new_lik);//与外链进行比较 得出差集 //将得到的差集 创建到 ve123_links $he_num = ceil(count($cha_lik)/$numm);//计算需要循环多少次 $fenge=array_chunk($cha_lik,$numm);//把数组分割成多少块数组 每块大小$numm for($i=0;$i<=$he_num;$i++) { $fen_url = array(); $fen_url = cmi($fenge[$i]); //多线程开始采集 foreach ((array)$fen_url as $url => $file) { $bianma = bianma($file); //获取得到htmlcode的编码 $file = Convert_File($file,$bianma); //转换所有编码为gb2312 $loy = clean_lry($file,$url,"html"); //过滤 file 中标题等 到数组 $title=$loy["title"]; //从数组中得到标题,赋值给title $pagesize=number_format(strlen($file)/1024, 0, ".", ""); $fulltxt=Html2Text($loy["fulltext"]); $description=$loy["description"]; //从数组中得到标题,赋值给description $keywords=$loy["keywords"]; //从数组中得到标题,赋值给keywords $lrymd5=md5($fulltxt); $updatetime=time(); if($title==""){$title=str_cut($fulltxt,65); } //根据url,更新内容 $array=array('url'=>$value,'lrymd5'=>$lrymd5,'title'=>$title,'fulltxt'=>$fulltxt,'description'=>$description,'keywords'=>$keywords,'pagesize'=>$pagesize,'updatetime'=>$updatetime); $db->insert("ve123_links",$array); echo "<font color=#C60A00><b>抓取到:</b></font>".$title; echo "<a href=".$url." target=_blank>".$url."</a><br>"; } } $newtime=time(); echo " --- <b>用时:</b>"; echo date("H:i:s",$newtime-$oldtime-28800); echo "<br>"; del_links_temp($site_id); } //抓全站--- 单线程 function all_url_dan($url,$old,$nei,$ooo,$site_id,$include_word,$not_include_word) { if(!is_url($url)) { return false;} global $db,$config; $snoopy = new Snoopy; //国外snoopy程序 $snoopy->fetchlry($url); $links=$snoopy->resulry; if(!is_array($links)) {return;} $links=check_wai($links,$nei,$url); $links=array_values(array_unique($links)); $title=$snoopy->title; $fulltxt=$snoopy->fulltxt; $lrymd5=md5($fulltxt); $pagesize=$snoopy->pagesize; $description=$snoopy->description; $keywords=$snoopy->keywords; $updatetime=time(); if($title==""){$title=str_cut($fulltxt,65); } //读取url,更新内容 $array=array('lrymd5'=>$lrymd5,'title'=>$title,'fulltxt'=>$fulltxt,'description'=>$description,'keywords'=>$keywords,'pagesize'=>$pagesize,'updatetime'=>$updatetime); $db->update("ve123_links",$array,"url='".$url."'"); $all_num = count($links); $temp_links=array(); $cha_temp=array(); //开始读取 ve123_links_temp 中所有site_id 为$site_id 的url 然后和抓取的 $links 数组比较,将得到的差集创建到 ve123_links_temp 中 $query=$db->query("select url from ve123_links_temp where url like '%".getdomain($url)."%'"); while($row=$db->fetch_array($query)) { $temp_links[]=rtrim($row[url],"/"); } $cha_temp=array_diff($links,$temp_links); foreach((array)$cha_temp as $value) { $arral=array('url'=>$value,'site_id'=>$site_id); $db->insert("ve123_links_temp",$arral); } //开始读取 ve123_links 中所有site_id 为 $site_id 的url 然后和抓取的 $links 数组比较,将得到的差集创建到 ve123_links 中 合集则输出 已存在了 $query=$db->query("select url from ve123_links where url like '%".getdomain($url)."%'"); while($row=$db->fetch_array($query)) { $new_links[]=rtrim($row[url],"/"); } $cha_links=array_diff($links,$new_links); $cha_num = count($cha_links); foreach((array)$cha_links as $value) { if(check_include($value, $include_word, $not_include_word )) { $array=array('url'=>$value,'site_id'=>$site_id,'level'=>'1'); $db->insert("ve123_links",$array); } } printLinksReport($cha_num, $all_num, $cl=0); echo "<a href=".$old." target=_blank>".$old. "</a>"; ob_flush(); flush(); } //抓全站--- 单线程---不用的 function add_all_url_ ($url,$old,$numm,$ooo,$site_id,$include_word,$not_include_word) { if(!is_url($url)) { return false;} global $db,$config; $snoopy = new Snoopy; //国外snoopy程序 $snoopy->fetchlry($url); $links=$snoopy->resulry; if(!is_array($links)) {return;} $links=check_wai($links,$numm,$url); $links=array_values(array_unique($links)); $title=$snoopy->title; $fulltxt=$snoopy->fulltxt; $lrymd5=md5($fulltxt); $pagesize=$snoopy->pagesize; $description=$snoopy->description; $keywords=$snoopy->keywords; $updatetime=time(); if($title==""){$title=str_cut($fulltxt,65); } //读取url,更新内容 $array=array('lrymd5'=>$lrymd5,'title'=>$title,'fulltxt'=>$fulltxt,'description'=>$description,'keywords'=>$keywords,'pagesize'=>$pagesize,'updatetime'=>$updatetime); $db->update("ve123_links",$array,"url='".$url."'"); $all_num = count($links); $temp_links=array(); $cha_temp=array(); //开始读取 ve123_links_temp 中所有site_id 为$site_id 的url 然后和抓取的 $links 数组比较,将得到的差集创建到 ve123_links_temp 中 $query=$db->query("select url from ve123_links_temp where url like '%".getdomain($url)."%'"); while($row=$db->fetch_array($query)) { $temp_links[]=rtrim($row[url],"/"); } $cha_temp=array_diff($links,$temp_links); foreach((array)$cha_temp as $value) { $arral=array('url'=>$value,'site_id'=>$site_id); $db->insert("ve123_links_temp",$arral); } //开始读取 ve123_links 中所有site_id 为 $site_id 的url 然后和抓取的 $links 数组比较,将得到的差集创建到 ve123_links 中 合集则输出 已存在了 $query=$db->query("select url from ve123_links where url like '%".getdomain($url)."%'"); while($row=$db->fetch_array($query)) { $new_links[]=rtrim($row[url],"/"); } $he_links=array_intersect($links,$new_links); $he_num = count($he_links); $cha_links=array_diff($links,$new_links); $cha_num = count($cha_links); foreach((array)$cha_links as $value) { if(check_include($value, $include_word, $not_include_word )) { $array=array('url'=>$value,'site_id'=>$site_id,'level'=>'1'); $db->insert("ve123_links",$array); } } printLinksReport($cha_num, $all_num, $cl=0); echo "<a href=".$old." target=_blank>".$old. "</a>"; ob_flush(); flush(); } function printLinksReport($cha_num, $all_num, $cl) { global $print_results, $log_format; $cha_html = " <font color=\"blue\">页面包含<b>$all_num</b>条链接</font>。 <font color=\"red\"><b>$cha_num</b>条新链接。</font>\n"; $no_html = " <font color=\"blue\">页面包含<b>$all_num</b>条链接</font>。 没有新链接。\n"; if($cha_num==0) {print $no_html; flush();} else{print $cha_html;} } function add_links_insite($link,$old,$numm,$ooo,$site_id,$include_word,$not_include_word) { if(!is_url($link)) { return false; } global $db,$config; /* $spider=new spider; //系统自带蜘蛛 echo "<b>网站编码</b>(默认GB2312)<b>:"; $spider->url($link); echo "</b><br>"; $links= $spider->get_insite_links(); */ //$site_url=GetSiteUrl($link); $url_old=GetSiteUrl($old); echo "原始页=".$url_old." - - <"; echo "首层 id=".$site_id."> - - <"; echo "包含字段=".$include_word.">"; echo "<br>"; /*if($ooo==0) { $site=$db->get_one("select * from ve123_sites where url='".$url_old."'"); $site_id=$site["site_id"]; $include_word=$site["include_word"]; $not_include_word=$site["not_include_word"]; $spider_depth=$site["spider_depth"]; } */ $snoopy = new Snoopy; //国外snoopy程序 $snoopy->fetchlinks($link); $links=$snoopy->results; $links=check_wai($links,$numm,$link); $links=array_values(array_unique($links)); foreach((array)$links as $value) { $row=$db->get_one("select * from ve123_links_temp where url='".$value."'"); if(empty($row)) { $arral=array('url'=>$value,'site_id'=>$site_id); $db->insert("ve123_links_temp",$arral); } $value=rtrim($value,"/"); $row=$db->get_one("select * from ve123_links where url='".$value."'"); if (check_include($value, $include_word, $not_include_word )) { if(empty($row)&&is_url($value)) { echo "<font color=#C60A00><b>抓取到:</b></font>"; $array=array('url'=>$value,'site_id'=>$site_id,'level'=>'1'); $db->insert("ve123_links",$array); } else { echo "<b>已存在了:</b>";} echo "<a href=".$value." target=_blank>".$value. "</a><br>"; ob_flush(); flush(); //$row=$db->get_one("select * from ve123_links_temp where url='".$value."'"); // if(empty($row)&&is_url($value)) // { // $array=array('url'=>$value,'site_id'=>$site_id); // $db->insert("ve123_links_temp",$array); // } } } } //只保留内链或者外链 function check_wai($lry_all,$nei,$url) { $lry_nei=array();//站内链接数组 $lry_wai=array();//站外链接数组 $new_url=getdomain($url); if($nei=="") { foreach ((array)$lry_all as $value) { $lry_nei[]=rtrim($value,"/"); } return $lry_nei; } foreach ((array)$lry_all as $value) { if(getdomain($value)==$new_url) { $lry_nei[]=rtrim($value,"/"); //$lry_nei[]=$value; } else { $lry_wai[]=rtrim($value,"/"); } } if($nei==1){return $lry_nei;} if($nei==2){return $lry_wai;} } //把内链和外链分开 function fen_link($lry_all,$url) { $data=array();//站外链接数组 $new_url=getdomain($url); foreach ((array)$lry_all as $value) { if(getdomain($value)==$new_url) { $data['nei'][]=rtrim($value,"/"); } else { $data['wai'][]=rtrim($value,"/"); } } return $data; } function check_include($link, $include_word, $not_include_word) { $url_word = Array (); $not_url_word = Array (); $is_shoulu = true; if ($include_word != "") { $url_word = explode(",", $include_word); } if ($not_include_word != "") { $not_url_word = explode(",", $not_include_word); } foreach ($not_url_word as $v_key) { $v_key = trim($v_key); if ($v_key != "") { if (substr($v_key, 0, 1) == '*') { if (preg_match(substr($v_key, 1), $link)) { $is_shoulu = false; break; } } else { if (!(strpos($link, $v_key) === false)) { $is_shoulu = false; break; } } } } if ($is_shoulu && $include_word != "") { $is_shoulu = false; foreach ($url_word as $v_key) { $v_key = trim($v_key); if ($v_key != "") { if (substr($v_key, 0, 1) == '*') { if (preg_match(substr($v_key, 1), $link)) { $is_shoulu = true; break 2; } } else { if (strpos($link, $v_key) !== false) { $is_shoulu = true; break; } } } } } return $is_shoulu; } function add_links_site_fromtemp($in_url) { global $db; $domain=getdomain($in_url); $query=$db->query("select * from ve123_links_temp where url like '%".$domain."%' and no_id='0'"); while($row=$db->fetch_array($query)) { @$db->query("update ve123_links_temp set no_id='1' where url='".$row["url"]."'"); add_links_insite($row["url"],$row["url"],1,1); //sleep(3); } //sleep(5); add_links_site_fromtemp($in_url) ; } function insert_links($url) { global $db,$config; $spider=new spider; $spider->url($url); $links= $spider->links(); $sites= $spider->sites(); foreach($sites as $value) { $site_url=GetSiteUrl($link); $site=$db->get_one("select * from ve123_sites where url='".$site_url."'"); $site_id=$site["site_id"]; $row=$db->get_one("select * from ve123_links where url='".$value."'"); if(empty($row)&&is_url($value)) { echo $value."<br>"; $array=array('url'=>$value,'site_id'=>$site_id,'level'=>'0'); $db->insert("ve123_links",$array); } else { echo "已存在:".$value."<br>"; } ob_flush(); flush(); //sleep(1); $row=$db->get_one("select * from ve123_sites where url='".$value."'"); if(empty($row)&&is_url($value)) { $array=array('url'=>$value,'spider_depth'=>$config["spider_depth"],'addtime'=>time()); $db->insert("ve123_sites",$array); } } //sleep(1); foreach($links as $value) { $row=$db->get_one("select * from ve123_links_temp where url='".$value."'"); if(empty($row)&&is_url($value)) { $array=array('url'=>$value); $db->insert("ve123_links_temp",$array); } } } function GetUrl_AllSite($in_url) { global $db; $query=$db->query("select * from ve123_links_temp where url like '%".$in_url."%' and updatetime<='".(time()-(86400*30))."'"); while($row=$db->fetch_array($query)) { @$db->query("update ve123_links_temp set updatetime='".time()."' where url='".$row["url"]."'"); insert_links($row["url"]); //sleep(3); } //sleep(5); GetUrl_AllSite($in_url) ; } function Updan_link($url,$site_id) { global $db; $row=$db->get_one("select * from ve123_links_temp where url='".$url."'"); if(empty($row)) { $arral=array('url'=>$url,'site_id'=>$site_id); $db->insert("ve123_links_temp",$arral); } $row=$db->get_one("select * from ve123_links where url like '%".$url."%'"); if(empty($row)) { echo "<font color=#C60A00><b>抓取到:</b></font>".$url."<br>"; $array=array('url'=>$url,'site_id'=>$site_id,'level'=>'1'); $db->insert("ve123_links",$array); } else { echo "已存在:".$url."<br>"; } } function Updan_zhua($url,$site_id) { global $db; $lrp = array(); $links = array(); $fen_link = array(); $nei_link = array(); $new_temp = array(); $cha_temp = array(); $lrp = cmi($url); $links = _striplinks($lrp[$url]); //从htmlcode中提取网址 $links = _expandlinks($links, $url); //补全网址 $fen_link=fen_link($links,$url); //把内链和外链分开 $nei_link=array_values(array_unique($fen_link[nei])); //过滤内链 重复的网址 //读出 ve123_sites_temp 中所有 site_id=-1 and no_id=0 $query=$db->query("select url from ve123_sites_temp where site_id='".$site_id."'"); while($row=$db->fetch_array($query)) { $new_temp[]=$row[url]; } $cha_temp=array_diff($nei_link,$new_temp);//与内链进行比较 得出差集 //将差集创建到 ve123_sites_temp 中 foreach((array)$cha_temp as $value) { $arral=array('url'=>$value,'site_id'=>$site_id,'no_id'=>0); $db->insert("ve123_sites_temp",$arral); } } function Update_link($url) { global $db,$bug_url; $is_success=FALSE; $is_shoulu=FALSE; /*$spider=new spider; $spider->url($url); $title=$spider->title; $fulltxt=$spider->fulltxt; $lrymd5=md5($spider->fulltxt); $pagesize=$spider->pagesize; $keywords=$spider->keywords; $htmlcode=$spider->htmlcode; $description=$spider->description;*/ $snoopy = new Snoopy; //国外snoopy程序 $snoopy->fetchtext($url); $title=$snoopy->title; $fulltxt=$snoopy->fulltxt; $lrymd5=md5($fulltxt); $pagesize=$snoopy->pagesize; $description=$snoopy->description; $keywords=$snoopy->keywords; //echo "fulltxt=".$fulltxt."<br>"; $updatetime=time(); //$site_url=GetSiteUrl($url); //$site=$db->get_one("select * from ve123_sites where url='".$site_url."'"); //$site_id=$site["site_id"]; //echo "site_id".$site["site_id"]."<br>"; if($title==""){$title=str_cut($fulltxt,65); } echo "<b><font color=#0Ae600>已更新</font></b>"; echo $title; $array=array('lrymd5'=>$lrymd5,'title'=>$title,'fulltxt'=>$fulltxt,'description'=>$description,'keywords'=>$keywords,'pagesize'=>$pagesize,'updatetime'=>$updatetime); //$db->query("update ve123_links set updatetime='".time()."' where url='".$url."'"); //更新时间 //$s=array(); //$s=explode("?",$title); //$domain=GetSiteUrl($url); //$site=$db->get_one("select * from ve123_sites where url='".$domain."'"); $db->update("ve123_links",$array,"url='".$url."'"); $is_success=TRUE; if(empty($bug_url)) { exit(); } return $is_success; } function Update_All_Link_($in_url='',$days,$qiangzhi) { global $db; $new_url=array(); $fen_url=array(); $fenge=array(); $numm=20;//开启多少线程 //if($qiangzhi==0){ $lry="and strlen(lrymd5)!=32";} //else { ;} if(empty($in_url)) { $sql="select url from ve123_links where length(lrymd5)!=32 order by link_id desc"; } else { $sql="select url from ve123_links where url like '%".getdomain($in_url)."%' and length(lrymd5)!=32 order by link_id desc"; } echo $sql."<br>"; $query=$db->query($sql); while($row=$db->fetch_array($query)) { $new_url[]=$row[url]; } $he_num = ceil(count($new_url)/$numm);//计算需要循环多少次 //echo "<br><b>需要循环多少次=</b>".$he_num."<br>"; $fenge=array_chunk($new_url,$numm);//把数组分割成多少块数组 每块大小$numm for($i=0;$i<=$he_num;$i++) //for($i=0;$i<=1;$i++) { $fen_url=cmi($fenge[$i]); //需要把得到的数组 (数组只包括 网址和源码) 分析 写入数据库 , foreach ((array)$fen_url as $url => $file) { $bianma = bianma($file); //获取得到htmlcode的编码 $file = Convert_File($file,$bianma); //转换所有编码为gb2312 $lry = clean_lry($file,$url,"html"); $title=$lry["title"]; //从数组中得到标题,赋值给title $pagesize=number_format(strlen($file)/1024, 0, ".", ""); $fulltxt=Html2Text($lry["fulltext"]); $description=$lry["description"]; //从数组中得到标题,赋值给description $keywords=$lry["keywords"]; //从数组中得到标题,赋值给keywords $lrymd5=md5($fulltxt); $updatetime=time(); if($title==""){$title=str_cut($fulltxt,65); } echo "<b><font color=#0Ae600>已更新</font></b>"; echo $title; echo "<a href=".$url." target=_blank>".$url. "</a><br>"; $array=array('lrymd5'=>$lrymd5,'title'=>$title,'fulltxt'=>$fulltxt,'description'=>$description,'keywords'=>$keywords,'pagesize'=>$pagesize,'updatetime'=>$updatetime); $db->update("ve123_links",$array,"url='".$url."'"); } } } function cmi($links,$killspace=TRUE,$forhtml=TRUE,$timeout=6,$header=0,$follow=1){ $res=array();//用于保存结果 $mh = curl_multi_init();//创建多curl对象,为了几乎同时执行 foreach ((array)$links as $i => $url) { $conn[$url]=curl_init($url);//若url中含有gb2312汉字,例如FTP时,要在传入url的时候处理一下,这里不用 curl_setopt($conn[$url], CURLOPT_TIMEOUT, $timeout);//此时间须根据页面的HTML源码出来的时间,一般是在1s内的,慢的话应该也不会6秒,极慢则是在16秒内 curl_setopt($conn[$url], CURLOPT_HEADER, $header);//不返回请求头,只要源码 curl_setopt($conn[$url],CURLOPT_RETURNTRANSFER,1);//必须为1 curl_setopt($conn[$url], CURLOPT_FOLLOWLOCATION, $follow);//如果页面含有自动跳转的代码如301或者302HTTP时,自动拿转向的页面 curl_multi_add_handle ($mh,$conn[$url]);//关键,一定要放在上面几句之下,将单curl对象赋给多对象 } //下面一大步的目的是为了减少cpu的无谓负担,暂时不明,来自php.net的建议,几乎是固定用法 do { $mrc = curl_multi_exec($mh,$active);//当无数据时或请求暂停时,active=true } while ($mrc == CURLM_CALL_MULTI_PERFORM);//当正在接受数据时 while ($active and $mrc == CURLM_OK) {//当无数据时或请求暂停时,active=true,为了减少cpu的无谓负担,这一步很难明啊 if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } foreach ((array)$links as $i => $url) { $cinfo=curl_getinfo($conn[$url]);//可用于取得一些有用的参数,可以认为是header $res[$url]=curl_multi_getcontent($conn[$url]); if(!$forhtml){//节约内存 $res[$url]=NULL; } /*下面这一段放一些高消耗的程序代码,用来处理HTML,我保留的一句=NULL是要提醒,及时清空对象释放内存,此程序在并发过程中如果源码太大,内在消耗严重 //事实上,这里应该做一个callback函数或者你应该将你的逻辑直接放到这里来,我为了程序可重复,没这么做 preg_match_all($preg,$res[$i],$matchlinks); $res[$i]=NULL;*/ curl_close($conn[$url]);//关闭所有对象 curl_multi_remove_handle($mh , $conn[$url]); //用完马上释放资源 } curl_multi_close($mh);$mh=NULL;$conn=NULL;$links=NULL; return $res; } function clean_lry($file, $url, $type) { $data=array(); $file = preg_replace("/<link rel[^<>]*>/i", " ", $file); //$file = preg_replace("@<!--sphider_noindex-->.*?<!--\/sphider_noindex-->@si", " ",$file); $file = preg_replace("@<!--.*?-->@si", " ",$file); $file = preg_replace("@<script[^>]*?>.*?</script>@si", " ",$file); $file = preg_replace("/&nbsp;/", " ", $file); $file = preg_replace("/&raquo;/", " ", $file); $file=str_replace("'","‘",$file); $regs = Array (); preg_match("/<meta +name *=[\"']?description[\"']? *content=[\"']?([^<>'\"]+)[\"']?/i", $file, $regs); if (isset ($regs)) { $description = $regs[1]; $file = str_replace($regs[0], "", $file); } $regs = Array (); preg_match("/<meta +name *=[\"']?keywords[\"']? *content=[\"']?([^<>'\"]+)[\"']?/i", $file, $regs); if (isset ($regs)) { $keywords = $regs[1]; $file = str_replace($regs[0], "", $file); } $regs = Array (); $keywords = preg_replace("/[, ]+/", " ", $keywords); if (preg_match("@<title *>(.*?)<\/title*>@si", $file, $regs)) { $title = trim($regs[1]); $file = str_replace($regs[0], "", $file); } $file = preg_replace("@<style[^>]*>.*?<\/style>@si", " ", $file); //create spaces between tags, so that removing tags doesnt concatenate strings $file = preg_replace("/<[\w ]+>/", "\\0 ", $file); $file = preg_replace("/<\/[\w ]+>/", "\\0 ", $file); $file = strip_tags($file); //$fulltext = $file; //$file .= " ".$title; $file = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $file); $file = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $file); $file = strtolower($file); $file = preg_replace("/&[a-z]{1,6};/", " ", $file); $file = preg_replace("/[\*\^\+\?\\\.\[\]\^\$\|\{\)\(\}~!\"\/@#?%&=`?><:,]+/", " ", $file); $file = preg_replace("/\s+/", " ", $file); //$data['fulltext'] = $fulltext; $data['fulltext'] = addslashes($file); $data['title'] = addslashes($title); $data['description'] = $description; $data['keywords'] = $keywords; return $data; } function bianma($file) { preg_match_all("/<meta.+?charset=([-\w]+)/i",$file,$rs); $chrSet=strtoupper(trim($rs[1][0])); return $chrSet; } function Convert_File($file,$charSet) { $conv_file = html_entity_decode($file); $charSet = strtoupper(trim($charSet)); if($charSet != "GB2312"&&$charSet != "GBK") { $file=convertfile($charSet,"GB2312",$conv_file); if($file==-1){ return -1; } } return $file; } function convertfile($in_charset, $out_charset, $str) { //if(function_exists('mb_convert_encoding')) //{ $in_charset=explode(',',$in_charset); $encode_arr = array('GB2312','GBK','UTF-8','ASCII','BIG5','JIS','eucjp-win','sjis-win','EUC-JP'); $cha_temp=array_intersect($encode_arr,$in_charset); $cha_temp=implode('',$cha_temp); if(empty($in_charset)||empty($cha_temp)) { $encoded = mb_detect_encoding($str, $encode_arr); $in_charset=$encoded; } if(empty($in_charset)){ return -1; } echo $in_charset; return mb_convert_encoding($str, $out_charset, $in_charset); /*} else { require_once PATH.'include/charset.func.php'; $in_charset = strtoupper($in_charset); $out_charset = strtoupper($out_charset); if($in_charset == 'UTF-8' && ($out_charset == 'GBK' || $out_charset == 'GB2312')) { return utf8_to_gbk($str); } if(($in_charset == 'GBK' || $in_charset == 'GB2312') && $out_charset == 'UTF-8') { return gbk_to_utf8($str); } return $str; }*/ } function Update_All_Link($in_url='',$days,$qiangzhi) { global $db; if(empty($in_url)) { //$sql="select * from ve123_links where updatetime<='".(time()-(86400*$days))."' order by link_id desc";//echo $days."<br>"; $sql="select * from ve123_links where updatetime+86400 <".time()." order by link_id ";//echo $days."<br>"; } else { $sql="select * from ve123_links where url like '%".getdomain($in_url)."%' order by link_id desc";//echo $days."<br>"; //$sql="select * from ve123_links where url like '%".$in_url."%' order by link_id desc";//echo $days."<br>"; } //$sql="select * from ve123_links order by link_id"; echo $sql."<br>"; $query=$db->query($sql); while($row=$db->fetch_array($query)) { if(is_url($row["url"])) { // echo "呵呵呵呵".$row["lrymd5"]."<br>"; ob_flush(); flush(); //sleep(1); //if($row["lrymd5"]==""){ Update_link($row["url"],$row["lrymd5"]); } if($qiangzhi==1){ Update_link($row["url"]); } else { if(strlen($row["lrymd5"])!=32){ Update_link($row["url"]); } else {echo ""; } } echo ""; } ////sleep(2); } // echo "<br><b>全部更新完成</b> 完成日期:"; // echo date("Y年m月d日 H:i:s",time()); //sleep(2); // Update_All_Link($in_url) ; } function url_ce($val, $parent_url, $can_leave_domain) { global $ext, $mainurl, $apache_indexes, $strip_sessids; $valparts = parse_url($val); $main_url_parts = parse_url($mainurl); //if ($valparts['host'] != "" && $valparts['host'] != $main_url_parts['host'] && $can_leave_domain != 1) {return '';} reset($ext); while (list ($id, $excl) = each($ext)) if (preg_match("/\.$excl$/i", $val)) return ''; if (substr($val, -1) == '\\') {return '';} if (isset($valparts['query'])) {if ($apache_indexes[$valparts['query']]) {return '';}} if (preg_match("/[\/]?mailto:|[\/]?javascript:|[\/]?news:/i", $val)) {return '';} if (isset($valparts['scheme'])) {$scheme = $valparts['scheme'];} else {$scheme ="";} if (!($scheme == 'http' || $scheme == '' || $scheme == 'https')) {return '';} $regs = Array (); while (preg_match("/[^\/]*\/[.]{2}\//", $valpath, $regs)) { $valpath = str_replace($regs[0], "", $valpath); } $valpath = preg_replace("/\/+/", "/", $valpath); $valpath = preg_replace("/[^\/]*\/[.]{2}/", "", $valpath); $valpath = str_replace("./", "", $valpath); if(substr($valpath,0,1)!="/") {$valpath="/".$valpath;} $query = ""; if (isset($val_parts['query'])) {$query = "?".$val_parts['query'];} if ($main_url_parts['port'] == 80 || $val_parts['port'] == "") {$portq = "";} else {$portq = ":".$main_url_parts['port'];} return $val; } function iframe_ce($val, $parent_url, $can_leave_domain) { global $ext, $mainurl, $apache_indexes, $strip_sessids; $valparts = parse_url($val); $main_url_parts = parse_url($mainurl); //if ($valparts['host'] != "" && $valparts['host'] != $main_url_parts['host'] && $can_leave_domain != 1) {return '';} reset($ext); while (list ($id, $excl) = each($ext)) if (preg_match("/\.$excl$/i", $val)) return ''; if (substr($val, -1) == '\\') {return '';} if (isset($valparts['query'])) {if ($apache_indexes[$valparts['query']]) {return '';}} if (preg_match("/[\/]?mailto:|[\/]?javascript:|[\/]?news:/i", $val)) {return '';} if (isset($valparts['scheme'])) {$scheme = $valparts['scheme'];} else {$scheme ="";} if (!($scheme == 'http' || $scheme == '' || $scheme == 'https')) {return '';} $regs = Array (); while (preg_match("/[^\/]*\/[.]{2}\//", $valpath, $regs)) { $valpath = str_replace($regs[0], "", $valpath); } $valpath = preg_replace("/\/+/", "/", $valpath); $valpath = preg_replace("/[^\/]*\/[.]{2}/", "", $valpath); $valpath = str_replace("./", "", $valpath); if(substr($valpath,0,1)!="/") {$valpath="/".$valpath;} $query = ""; if (isset($val_parts['query'])) {$query = "?".$val_parts['query'];} if ($main_url_parts['port'] == 80 || $val_parts['port'] == "") {$portq = "";} else {$portq = ":".$main_url_parts['port'];} return $val; } function _striplinks($document) { $match = array(); $links = array(); preg_match_all("'<\s*(a\s.*?href|[i]*frame\s.*?src)\s*=\s*([\'\"])?([+:%\/\?~=&\\\(\),._a-zA-Z0-9-]*)'isx",$document,$links,PREG_PATTERN_ORDER); foreach ($links[3] as $val) { if (($a = url_ce($val, $url, $can_leave_domain)) != '') { $match[] = $a; } $checked_urls[$val[1]] = 1; } return $match; } function _expandlinks($links,$URI) { preg_match("/^[^\?]+/",$URI,$match); $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); $match = preg_replace("|/$|","",$match); $match_part = parse_url($match); $match_root = $match_part["scheme"]."://".$match_part["host"]; $URI_PARTS = parse_url($URI); $host = $URI_PARTS["host"]; $search = array( "|^http://".preg_quote($host)."|i", "|^(\/)|i", "|^(?!http://)(?!mailto:)|i", "|/\./|", "|/[^\/]+/\.\./|" ); $replace = array( "", $match_root."/", $match."/", "/", "/" ); $expandedLinks = preg_replace($search,$replace,$links); return $expandedLinks; } function foothtml() { echo "<div style=\"text-align:center;\"><a target=\"_blank\" href=\"http://www.php.com\"> Php</a></div>"; } ?> ``` ```
java poi 导出excl怎么添加函数
用poi操作excl怎么在导出的时候给添加函数
请问,linux下消息队列通信为什么收不到消息
A1.c #include stdio.h> #include stdlib.h> #include string.h> #include sys/types.h> #include sys/msg.h> #include unistd.h> #include sys/ipc.h> int main(){ int ret = -1; int msg_flags, smsg_id ,rmsg_id;/*创建消息队列函数所用的标志位,以及收消息与发消息的队列id*/ key_t key1,key2;/*队列的键值*/ struct msgmbuf{/*消息的缓冲区结构*/ int mtype; char mtext[10]; }; struct msgmbuf msg_mbuf;/*创建消息缓冲区*/ int msg_sflags,msg_rflags;/*收发消息函数所用的标志位*/ char *msgpath1 = "/mnt/hgfs/";/*消息key1产生所用的路径*/ char *msgpath2 = "/mnt/hgfs/sourcecode";/*消息key2产生所用的路径*/ key1 = ftok(msgpath1,'b');/*产生key1*/ key2 = ftok(msgpath2,'a');/*产生key2*/ if(key1 != -1 || key2 != -1)/*产生key成功*/ { printf("成功建立KEY\n"); } else/*产生key失败*/ { printf("建立KEY失败\n"); } msg_flags = IPC_CREAT;//|IPC_EXCL; /*设置创建消息的标志位*/ smsg_id = msgget(key1, msg_flags|0666); /*建立收消息的消息队列*/ rmsg_id = msgget(key2, msg_flags|0666); /*建立发消息的消息队列*/ if( -1 == smsg_id || -1 == rmsg_id) { printf("消息建立失败\n"); return 0; } pid_t pid; pid = fork();/*通过fork()创建子进程,主进程进行发消息,子进程进行收消息*/ while(1){ if(pid != 0){/*主进程*/ msg_sflags = IPC_NOWAIT;/*当消息队列满了的时候不等待*/ msg_mbuf.mtype = 10;/*设置发送的消息类型*/ sleep(1); char *content; content = (char*)malloc(10*sizeof(char)); printf("input:\n"); scanf("%s",content);/*用户输入内容*/ if(strncmp(content,"end",3) == 0)/*如果前三个字符为end,则跳出循环*/ break; memcpy(msg_mbuf.mtext,content,10);/*复制字符串*/ ret = msgsnd(smsg_id, &msg_mbuf, 10, msg_sflags);/*发送消息*/ if( -1 == ret) { printf("发送消息失败\n"); } } else{/*子进程*/ sleep(1); msg_mbuf.mtype = 10;/*设置收消息的类型*/ msg_rflags = IPC_NOWAIT;//|MSG_NOERROR; ret = msgrcv(rmsg_id, &msg_mbuf,10,10,msg_rflags);/*接收消息*/ if( -1 == ret) { /*可添加出错处理等*/ } else { printf("接收消息成功,长度:%d\n",ret); printf("content:%s\n",msg_mbuf.mtext); } } } ret = msgctl(rmsg_id, IPC_RMID,NULL);/*删除收消息的队列*/ if(-1 == ret) { printf("删除消息失败\n"); return 0; } return 0; } A2.c #include stdio.h> #include stdlib.h> #include string.h> #include sys/types.h> #include sys/msg.h> #include unistd.h> #include sys/ipc.h> int main(){ int ret = -1; int msg_flags, smsg_id ,rmsg_id;/*创建消息队列函数所用的标志位,以及收消息与发消息的队列id*/ key_t key1,key2;/*队列的键值*/ struct msgmbuf{/*消息的缓冲区结构*/ int mtype; char mtext[10]; }; struct msgmbuf msg_mbuf;/*创建消息缓冲区*/ int msg_sflags,msg_rflags;/*收发消息函数所用的标志位*/ char *msgpath1 = "/mnt/hgfs/";/*消息key1产生所用的路径*/ char *msgpath2 = "/mnt/hgfs/sourcecode";/*消息key2产生所用的路径*/ key1 = ftok(msgpath1,'b');/*产生key1*/ key2 = ftok(msgpath2,'a');/*产生key2*/ if(key1 != -1 || key2 != -1)/*产生key成功*/ { printf("成功建立KEY\n"); } else/*产生key失败*/ { printf("建立KEY失败\n"); } msg_flags = IPC_CREAT;//|IPC_EXCL; /*设置创建消息的标志位*/ smsg_id = msgget(key2, msg_flags|0666); /*建立收消息的消息队列*/ rmsg_id = msgget(key1, msg_flags|0666); /*建立发消息的消息队列*/ if( -1 == smsg_id || -1 == rmsg_id) { printf("消息建立失败\n"); return 0; } pid_t pid; pid = fork();/*通过fork()创建子进程,主进程进行发消息,子进程进行收消息*/ while(1){ if(pid != 0){/*主进程*/ msg_sflags = IPC_NOWAIT;/*当消息队列满了的时候不等待*/ msg_mbuf.mtype = 10;/*设置发送的消息类型*/ sleep(1); char *content; content = (char*)malloc(10*sizeof(char)); printf("input:\n"); scanf("%s",content);/*用户输入内容*/ if(strncmp(content,"end",3) == 0)/*如果前三个字符为end,则跳出循环*/ break; memcpy(msg_mbuf.mtext,content,10);/*复制字符串*/ ret = msgsnd(smsg_id, &msg_mbuf, 10, msg_sflags);/*发送消息*/ if( -1 == ret) { printf("发送消息失败\n"); } } else{/*子进程*/ sleep(1); msg_mbuf.mtype = 10;/*设置收消息的类型*/ msg_rflags = IPC_NOWAIT;//|MSG_NOERROR; ret = msgrcv(rmsg_id, &msg_mbuf,10,10,msg_rflags);/*接收消息*/ if( -1 == ret) { /*可添加出错处理等*/ } else { printf("接收消息成功,长度:%d\n",ret); printf("content:%s\n",msg_mbuf.mtext); } } } ret = msgctl(rmsg_id, IPC_RMID,NULL);/*删除收消息的队列*/ if(-1 == ret) { printf("删除消息失败\n"); return 0; } return 0; } 头文件<>无法识别,均删去了<
关于linux中truncate函数的问题。
为什么我使用ftruncate截断文件后文件大小确实改变了,但是用read读取文件的内容还是截断之前的呢? ``` int main(void) { //创建文件 int new_fd = open("file/a",O_RDWR|O_CREAT|O_EXCL,0644); if(-1==new_fd) { printf("%d: ",__LINE__-3); perror("creat"); exit(-1); } //打开文件 int old_fd = open("file/file_test",O_RDWR); if(-1==old_fd) { printf("%d: ",__LINE__-3); perror("open"); exit(-1); } //复制文件 char buff[1024]; while(read(old_fd,buff,sizeof(buff))) { int res = write(new_fd,buff,strlen(buff)); if(-1==res) { printf("%d: ",__LINE__-3); perror("write"); close(new_fd); close(old_fd); exit(-1); } memset(buff,sizeof(buff),0); } memset(buff,sizeof(buff),0); close(old_fd); //读出修改后的文件 lseek(new_fd,0,SEEK_SET); while(read(new_fd,buff,sizeof(buff))) { printf("%s",buff); memset(buff,sizeof(buff),0); } printf("\n\n"); //获得修改过后的文件的信息 struct stat st; if(-1==fstat(new_fd,&st)) { printf("%d: ",__LINE__-3); perror("stat"); close(new_fd); exit(-1); } printf("文件大小为%d\n",st.st_size); printf("文件最后修改时间为%s",ctime(&st.st_mtime)); printf("文件权限为%o\n\n",st.st_mode&0777); //截取前100个字节 if(-1==ftruncate(new_fd,100)) { printf("%d: ",__LINE__-3); perror("truncate"); close(new_fd); exit(-1); } close(new_fd); //先关闭文件描述符 new_fd = open("file/a",O_RDWR);//再次打开 if(-1==new_fd) { printf("%d: ",__LINE__-3); perror("creat"); exit(-1); } #ifdef DE if(-1==fstat(new_fd,&st)) { printf("%d: ",__LINE__-3); perror("stat"); close(new_fd); exit(-1); } printf("文件大小为%d\n",st.st_size); printf("文件最后修改时间为%s",ctime(&st.st_mtime)); printf("文件权限为%o\n\n",st.st_mode&0777); #endif //读出文件 memset(buff,sizeof(buff),0); lseek(new_fd,0,SEEK_SET); while(read(new_fd,buff,sizeof(buff))) { printf("%s",buff); memset(buff,sizeof(buff),0); } printf("\n\n"); //改变新建文件的权限 close(new_fd); remove("file/4_file"); return 0; } ```
关于HOOK word程序内部函数实现,解密的问题
我有一个word的加密文件,从一个工具里把这个加密文件解密后显示出来。目前可以 实现的是对于docx,pptx,excl,txt的文件格式都可以成功了,但是对于doc这一类的office 2003 的程序生成出来的加密,无法读取。图1 是我工具正常读取到的docx的解密文件,图2是 我读取doc文件后出现的结果,没东西显示出来,图3是我读取正常没有加密的doc的log, 图4的是我读取加密doc文件的log,两边的log就是从图中这个位置开始不一样了 现在就是找不到原因在哪里,不知道怎么改可以正常读取这个doc文件了![图片1](https://img-ask.csdn.net/upload/201803/13/1520928298_480855.jpg)![2](https://img-ask.csdn.net/upload/201803/13/1520928333_221767.png)![3](https://img-ask.csdn.net/upload/201803/13/1520928195_729634.png)![4](https://img-ask.csdn.net/upload/201803/13/1520928222_455326.png)
建一个窗体,获取选择的文件路径和输入框中的ID,传输给查询程序。
![图片说明](https://img-ask.csdn.net/upload/201801/22/1516589684_320206.png) 效果如图。 点击上传按钮,能够选择本机的excl文件。获取路径。 输入框中输入数字ID 然后点击查询。(如果ID没有,或者文件路径没有,提示需要输入ID,或者需要选择文件) 点查询后,能够将ID和路径传给查询java。 查询的java已经写好了。 现在需要的是怎么建立这个窗体,来实现功能。 下面是窗体代码(需要修改的,我只是实现了界面排版): package test; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import excel.ExcelOperate; public class AbsolutePosition extends JFrame implements ActionListener { private JButton b1; private JScrollPane pane; private JTextArea area; public AbsolutePosition() { setTitle("本窗体使用绝对布局"); // 设置该窗体的标题 setLayout(null); // 使该窗体取消布局管理器设置 setBounds((Toolkit.getDefaultToolkit().getScreenSize().width -500)/2, (Toolkit.getDefaultToolkit().getScreenSize().height - 300)/2, 400, 400); // 绝对定位窗体的位置与大小 Container c = getContentPane(); // 创建容器对象 Label lb1 = new Label ("选择文件:"); b1 = new JButton("点击选择"); // 创建按钮 b1.addActionListener(this);//b1这个实例(按钮等)添加事件监听接口,this表示当前类的对象,在一个类里,你不需要new他的实例就直接可以用this调用它的方法和属性 area = new JTextArea(); pane = new JScrollPane(area); Label lb2 = new Label ("员工ID:"); JButton b2 = new JButton("查询"); // 创建按钮 JTextField jt=new JTextField();//创建输入框 lb1.setBounds(30, 30, 120, 30); // 设置文本的位置与大小 lb2.setBounds(30, 80, 120, 30); b1.setBounds(140, 30, 120, 30); // 设置按钮的位置与大小 jt.setBounds(140, 80, 100, 30);//设置文本框位置和大小 b2.setBounds(140, 150, 100, 30); c.add(b1); // 将按钮添加到容器中 this.add(pane); c.add(b2); c.add(lb1); c.add(jt); c.add(lb2); setVisible(true); // 使窗体可见 // 设置窗体关闭方式 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } // 按钮事件 public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser();// 文件选择对话框 chooser.setAcceptAllFileFilterUsed(false);// 取消所有文件过滤项 chooser.setFileFilter(new FileNameExtensionFilter("Excel文件", "xls"));// 设置只过滤扩展名为.xls的Excel文件 //String firstNum = jt.getText();//获取输入框值 int i = chooser.showOpenDialog(this);// 打开窗口 if (i == JFileChooser.APPROVE_OPTION) { this.setLocation(0, 0); this.setSize(Toolkit.getDefaultToolkit().getScreenSize()); //new ExcelOperate(area, chooser.getSelectedFile().getAbsolutePath())//调用ExcelOperate // .parseExcel(); //String B=(String)chooser.getSelectedFile().getAbsolutePath();//B为文件路径 //System.out.println(B); } } public static void main(String[] args) { new AbsolutePosition(); } } 下面是查询主代码 public static void main(String[] args) throws Exception { Car fy = new Car(); URL url = new java.net.URL("http://********");//这个是费用接口 //excel路径 String excel_file_path = "D:/cheliang.xls"; //获取excel数据 String A= new String(); String id="16215288";//员工ID List<LinkedHashMap<String,Object>> dataList = fy.getMsgInfoFromExcel(excel_file_path); for(LinkedHashMap<String,Object> dataMap : dataList){ String _cjh = dataMap.get("车架号(必填)")==null?"":dataMap.get("车架号(必填)").toString(); String _xm = dataMap.get("被保险人(必填)")==null?"":dataMap.get("被保险人(必填)").toString(); String _tel = dataMap.get("手机号")==null?"":dataMap.get("手机号").toString(); StringBuffer str = new StringBuffer(); str.append("<Request><VinNo>"); str.append(_cjh); str.append("</VinNo><CustomerName>"); str.append(_xm); str.append("</CustomerName><Mobile>"); str.append(_tel); str.append("</Mobile><IdentityCard></IdentityCard><LoginID>"); str.append(id); str.append("</LoginID></Request>"); URLConnection con = url.openConnection(); con.setUseCaches(false); con.setDoOutput(true); con.setDoInput(true); DataOutputStream dataOut = new DataOutputStream(con.getOutputStream()); String msg = str.toString(); //调用发送方法 //fy.sendMsg(msg, dataOut, con); //String carInfo=fy.sendMsg(msg, dataOut, con); String carInfo=sendMsg(msg, dataOut, con); if(carInfo.equals("车架号校验失败")) { A=A+"<Response> <VinNo>"+_cjh+"</VinNo> <CustomerName>"+_xm+"</CustomerName> <Mobile>"+carInfo+"</Mobile> <IdentityCard></IdentityCard> <ReturnMsgList> <ReturnMsg> <CarID></CarID> <CI__PolicyNo></CI__PolicyNo> <BZ__PolicyNo></BZ__PolicyNo> <LicenseNo></LicenseNo> <EngineNo></EngineNo> <FamilyType></FamilyType> <FamilyNewName></FamilyNewName> <EndDate></EndDate> <InsuredCode></InsuredCode> <ClaimCount></ClaimCount> <ClaimOldCount></ClaimOldCount> <NodamYearsBI></NodamYearsBI> <Age></Age> <ModelCode></ModelCode> <Message>"+carInfo+"</Message> </ReturnMsg> </ReturnMsgList></Response>"; }/*else if(carInfo == null || str.length() <= 0){ A=A+"<Response> <VinNo>"+_cjh+"</VinNo> <CustomerName>"+_xm+"</CustomerName> <Mobile>"+"获取为空"+"</Mobile> <IdentityCard></IdentityCard> <ReturnMsgList> <ReturnMsg> <CarID></CarID> <CI__PolicyNo></CI__PolicyNo> <BZ__PolicyNo></BZ__PolicyNo> <LicenseNo></LicenseNo> <EngineNo></EngineNo> <FamilyType></FamilyType> <FamilyNewName></FamilyNewName> <EndDate></EndDate> <InsuredCode></InsuredCode> <ClaimCount></ClaimCount> <ClaimOldCount></ClaimOldCount> <NodamYearsBI></NodamYearsBI> <Age></Age> <ModelCode></ModelCode> <Message>"+carInfo+"</Message> </ReturnMsg> </ReturnMsgList></Response>"; }*/else { A=A+carInfo; } OutExcel oed = new OutExcel(); oed.outExcel(A); dataOut.flush(); dataOut.close(); } } 主程序中的:excel_file_path和id希望能通过窗口获取过来。当然,如果用页面实现也可以。 欢迎大神私聊解决
java.lang.OutOfMemoryError: PermGen space
在服务器中添加一个SSH项目时,服务器运行一段时间后报错。 错误如下: 三月 06, 2017 5:45:50 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 21784 ms 三月 06, 2017 5:46:35 下午 org.apache.jasper.compiler.TldLocationsCache tldScanJar 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 三月 06, 2017 6:41:24 下午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom 信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [468] milliseconds. 三月 06, 2017 7:00:53 下午 org.quartz.core.JobRunShell run 严重: Job HtmlChannelJob.HtmlChannelJob8757c397-a53d-4c3d-84a0-929aac8e6db5 threw an unhandled Exception: java.lang.OutOfMemoryError: PermGen space 原服务器中有2个项目,把新加的项目war包直接放入webapps中。运行几个小时后出现了内存溢出的错误。 服务器tomcat配置如下![图片说明](https://img-ask.csdn.net/upload/201703/07/1488857464_691095.png) 新加的SSH项目有 excl导入导出功能,代码如下: ``` package zcib.recruitment.action; import zcib.recruitment.action.utils.UploadFile; import zcib.recruitment.domain.Student; import zcib.recruitment.service.StudentService; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.struts2.ServletActionContext; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.interceptor.ServletRequestAware; import com.opensymphony.xwork2.ActionSupport; public class AddStudentAction extends ActionSupport implements ServletRequestAware { private InputStream excelFile; private File uploadFile; private String uploadFileFileName; private StudentService studentService; private Student student; private String verifyCode; private HttpServletRequest request; // 进入页面查询数据 public String listAll() { HttpServletRequest request = ServletActionContext.getRequest(); List<Student> sList = studentService.findAll(); request.setAttribute("list", sList); return "listAll"; } // 导出Excel public String ExcelExport() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); String ids = request.getParameter("ids"); List<Student> list = new ArrayList<Student>(); String[] array = ids.split(","); int[] id = new int[array.length]; for (int i = 0; i < id.length; i++) { Student student = studentService .findById(Integer.valueOf(array[i])); list.add(student); } Workbook workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet("学生信息"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("考号"); row.createCell(1).setCellValue("姓名"); row.createCell(2).setCellValue("身份证号"); row.createCell(3).setCellValue("性别"); row.createCell(4).setCellValue("备注"); CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); for (int i = 1; i <= list.size(); i++) { Student stu = list.get(i - 1); row = sheet.createRow(i); row.createCell(0).setCellValue(stu.getExamId()); row.createCell(1).setCellValue(stu.getName()); row.createCell(2).setCellValue(stu.getMemberId()); row.createCell(3).setCellValue(stu.getSex()); row.createCell(4).setCellValue(stu.getRemark()); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); workbook.write(baos); excelFile = new ByteArrayInputStream(baos.toByteArray()); baos.close(); return "excel"; } // 导入Excel public String ExcelInto() throws Exception { String directory = "/file"; String targetDirectory = ServletActionContext.getServletContext().getRealPath(directory); File target = UploadFile.Upload(uploadFile, uploadFileFileName,targetDirectory); List<Student> sList = new ArrayList<Student>(); excelFile = new FileInputStream(target); Workbook wb = new HSSFWorkbook(excelFile); Sheet sheet = wb.getSheetAt(0); int rowNum = sheet.getLastRowNum() + 1; for (int i = 1; i < rowNum; i++) { Student student = new Student(); Row row = sheet.getRow(i); int cellNum = row.getLastCellNum(); for (int j = 0; j < cellNum; j++) { Cell cell = row.getCell(j); String cellValue = null; switch (cell.getCellType()) { // 判断excel单元格内容的格式,并对其进行转换,以便插入数据库 case 0: cellValue = String .valueOf((int) cell.getNumericCellValue()); break; case 1: cellValue = cell.getStringCellValue(); break; case 2: cellValue = String .valueOf((int) cell.getNumericCellValue()); break; case 3: cellValue = cell.getStringCellValue(); break; case 4: cellValue = cell.getStringCellValue(); break; } switch (j) {// 通过列数来判断对应插如的字段 case 0: student.setExamId(cellValue); break; case 1: student.setName(cellValue); break; case 2: student.setMemberId(cellValue); break; case 3: student.setSex(Integer.valueOf(cellValue)); break; case 4: student.setRemark(cellValue); } } Student stu = studentService.findByExamId(student.getExamId());//判断数据库中是否拥有重复学生 if(stu==null){ sList.add(student); } } studentService.save(sList); return "success"; } public void setServletRequest(HttpServletRequest request) { this.request = request; } public Student getStudent() { return student; } public void setStudent(Student student) { this.student = student; } public String getVerifyCode() { return verifyCode; } public void setVerifyCode(String verifyCode) { this.verifyCode = verifyCode; } public StudentService getStudentService() { return studentService; } public void setStudentService(StudentService studentService) { this.studentService = studentService; } public InputStream getExcelFile() { return excelFile; } public void setExcelFile(InputStream excelFile) { this.excelFile = excelFile; } public File getUploadFile() { return uploadFile; } public void setUploadFile(File uploadFile) { this.uploadFile = uploadFile; } public String getUploadFileFileName() { return uploadFileFileName; } public void setUploadFileFileName(String uploadFileFileName) { this.uploadFileFileName = uploadFileFileName; } public HttpServletRequest getRequest() { return request; } public void setRequest(HttpServletRequest request) { this.request = request; } } ``` struts配置如下: ``` <action name="export_*" class="zcib.recruitment.action.AddStudentAction" method="{1}"> <result name="listAll">/recruitmentInfoList.jsp</result> <result name="success" type="redirect">export_listAll.action</result> <result name="excel" type="stream"> <param name="contentType">application/vnd.ms-excel</param> <param name="contentDisposition">attachment;filename="AllUsers.xls"</param> <param name="inputName">excelFile</param> </result> <result name="pdf" type="stream"> <param name="contentType">application/pdf; charset=gb2312</param> <param name="inputName">excelFile</param> <param name="contentDisposition">attachment; filename="contract.pdf"</param> <param name="bufferSize">2048</param> </result> <result name="word" type="redirect">export_listAll.action</result> </action> ``` 求大神帮忙看一下 内存溢出到底什么问题。
linux系统下使用snmpset命令始终报错,,,
[root@localhost 桌面]# snmpset -v2c -c public -On localhost system.sysName.0 s linux Error in packet. Reason: noAccess Failed object: .1.3.6.1.2.1.1.5.0 始终处于这个错误,请各路大神帮帮我,感激不尽,,,,我的conmpd.conf文件是: ############################################################################### # # snmpd.conf: # An example configuration file for configuring the ucd-snmp snmpd agent. # ############################################################################### # # This file is intended to only be as a starting point. Many more # configuration directives exist than are mentioned in this file. For # full details, see the snmpd.conf(5) manual page. # # All lines beginning with a '#' are comments and are intended for you # to read. All other lines are configuration commands for the agent. ############################################################################### # Access Control ############################################################################### # As shipped, the snmpd demon will only respond to queries on the # system mib group until this file is replaced or modified for # security purposes. Examples are shown below about how to increase the # level of access. # By far, the most common question I get about the agent is "why won't # it work?", when really it should be "how do I configure the agent to # allow me to access it?" # # By default, the agent responds to the "public" community for read # only access, if run out of the box without any configuration file in # place. The following examples show you other ways of configuring # the agent so that you can change the community names, and give # yourself write access to the mib tree as well. # # For more information, read the FAQ as well as the snmpd.conf(5) # manual page. #### # First, map the community name "public" into a "security name" # sec.name source community com2sec notConfigUser default public #### # Second, map the security name into a group name: # groupName securityModel securityName group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser #### # Third, create a view for us to let the group have rights to: # Make at least snmpwalk -v 1 localhost -c public system fast again. # name incl/excl subtree mask(optional) view systemview included .1 view systemview included .1.3.6.1.2.1.1 view systemview included .1.3.6.1.2.1.25.1.1 #### # Finally, grant the group read-only access to the systemview view. # group context sec.model sec.level prefix read write notif access notConfigGroup "" any noauth exact systemview none none # ----------------------------------------------------------------------------- # Here is a commented out example configuration that allows less # restrictive access. # YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY # KNOWN AT YOUR SITE. YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO # SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE. ## sec.name source community #com2sec local localhost COMMUNITY #com2sec mynetwork NETWORK/24 COMMUNITY ## group.name sec.model sec.name #group MyRWGroup any local #group MyROGroup any mynetwork # #group MyRWGroup any otherv3user #... ## incl/excl subtree mask #view all included .1 80 ## -or just the mib2 tree- #view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc ## context sec.model sec.level prefix read write notif #access MyROGroup "" any noauth 0 all none none #access MyRWGroup "" any noauth 0 all all all ############################################################################### # Sample configuration to make net-snmpd RFC 1213. # Unfortunately v1 and v2c don't allow any user based authentification, so # opening up the default config is not an option from a security point. # # WARNING: If you uncomment the following lines you allow write access to your # snmpd daemon from any source! To avoid this use different names for your # community or split out the write access to a different community and # restrict it to your local network. # Also remember to comment the syslocation and syscontact parameters later as # otherwise they are still read only (see FAQ for net-snmp). # # First, map the community name "public" into a "security name" # sec.name source community #com2sec notConfigUser default public # Second, map the security name into a group name: # groupName securityModel securityName #group notConfigGroup v1 notConfigUser #group notConfigGroup v2c notConfigUser # Third, create a view for us to let the group have rights to: # Open up the whole tree for ro, make the RFC 1213 required ones rw. # name incl/excl subtree mask(optional) #view roview included .1 #view rwview included system.sysContact #view rwview included system.sysName #view rwview included system.sysLocation #view rwview included interfaces.ifTable.ifEntry.ifAdminStatus #view rwview included at.atTable.atEntry.atPhysAddress #view rwview included at.atTable.atEntry.atNetAddress #view rwview included ip.ipForwarding #view rwview included ip.ipDefaultTTL #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteDest #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteIfIndex #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric1 #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric2 #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric3 #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric4 #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteType #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteAge #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteMask #view rwview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric5 #view rwview included ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaIfIndex #view rwview included ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaPhysAddress #view rwview included ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaNetAddress #view rwview included ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType #view rwview included tcp.tcpConnTable.tcpConnEntry.tcpConnState #view rwview included egp.egpNeighTable.egpNeighEntry.egpNeighEventTrigger #view rwview included snmp.snmpEnableAuthenTraps # Finally, grant the group read-only access to the systemview view. # group context sec.model sec.level prefix read write notif #access notConfigGroup "" any noauth exact roview rwview none ############################################################################### # System contact information # # It is also possible to set the sysContact and sysLocation system # variables through the snmpd.conf file: syslocation Unknown (edit /etc/snmp/snmpd.conf) syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) # Example output of snmpwalk: # % snmpwalk -v 1 localhost -c public system # system.sysDescr.0 = "SunOS name sun4c" # system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.sunos4 # system.sysUpTime.0 = Timeticks: (595637548) 68 days, 22:32:55 # system.sysContact.0 = "Me <me@somewhere.org>" # system.sysName.0 = "name" # system.sysLocation.0 = "Right here, right now." # system.sysServices.0 = 72 ############################################################################### # Logging # # We do not want annoying "Connection from UDP: " messages in syslog. # If the following option is commented out, snmpd will print each incoming # connection, which can be useful for debugging. dontLogTCPWrappersConnects yes # ----------------------------------------------------------------------------- ############################################################################### # Process checks. # # The following are examples of how to use the agent to check for # processes running on the host. The syntax looks something like: # # proc NAME [MAX=0] [MIN=0] # # NAME: the name of the process to check for. It must match # exactly (ie, http will not find httpd processes). # MAX: the maximum number allowed to be running. Defaults to 0. # MIN: the minimum number to be running. Defaults to 0. # # Examples (commented out by default): # # Make sure mountd is running proc mountd # Make sure there are no more than 4 ntalkds running, but 0 is ok too. proc ntalkd 4 # Make sure at least one sendmail, but less than or equal to 10 are running. proc sendmail 10 1 # A snmpwalk of the process mib tree would look something like this: # # % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.2 # enterprises.ucdavis.procTable.prEntry.prIndex.1 = 1 # enterprises.ucdavis.procTable.prEntry.prIndex.2 = 2 # enterprises.ucdavis.procTable.prEntry.prIndex.3 = 3 # enterprises.ucdavis.procTable.prEntry.prNames.1 = "mountd" # enterprises.ucdavis.procTable.prEntry.prNames.2 = "ntalkd" # enterprises.ucdavis.procTable.prEntry.prNames.3 = "sendmail" # enterprises.ucdavis.procTable.prEntry.prMin.1 = 0 # enterprises.ucdavis.procTable.prEntry.prMin.2 = 0 # enterprises.ucdavis.procTable.prEntry.prMin.3 = 1 # enterprises.ucdavis.procTable.prEntry.prMax.1 = 0 # enterprises.ucdavis.procTable.prEntry.prMax.2 = 4 # enterprises.ucdavis.procTable.prEntry.prMax.3 = 10 # enterprises.ucdavis.procTable.prEntry.prCount.1 = 0 # enterprises.ucdavis.procTable.prEntry.prCount.2 = 0 # enterprises.ucdavis.procTable.prEntry.prCount.3 = 1 # enterprises.ucdavis.procTable.prEntry.prErrorFlag.1 = 1 # enterprises.ucdavis.procTable.prEntry.prErrorFlag.2 = 0 # enterprises.ucdavis.procTable.prEntry.prErrorFlag.3 = 0 # enterprises.ucdavis.procTable.prEntry.prErrMessage.1 = "No mountd process running." # enterprises.ucdavis.procTable.prEntry.prErrMessage.2 = "" # enterprises.ucdavis.procTable.prEntry.prErrMessage.3 = "" # enterprises.ucdavis.procTable.prEntry.prErrFix.1 = 0 # enterprises.ucdavis.procTable.prEntry.prErrFix.2 = 0 # enterprises.ucdavis.procTable.prEntry.prErrFix.3 = 0 # # Note that the errorFlag for mountd is set to 1 because one is not # running (in this case an rpc.mountd is, but thats not good enough), # and the ErrMessage tells you what's wrong. The configuration # imposed in the snmpd.conf file is also shown. # # Special Case: When the min and max numbers are both 0, it assumes # you want a max of infinity and a min of 1. # # ----------------------------------------------------------------------------- ############################################################################### # Executables/scripts # # # You can also have programs run by the agent that return a single # line of output and an exit code. Here are two examples. # # exec NAME PROGRAM [ARGS ...] # # NAME: A generic name. The name must be unique for each exec statement. # PROGRAM: The program to run. Include the path! # ARGS: optional arguments to be passed to the program # a simple hello world exec echotest /bin/echo hello world # Run a shell script containing: # # #!/bin/sh # echo hello world # echo hi there # exit 35 # # Note: this has been specifically commented out to prevent # accidental security holes due to someone else on your system writing # a /tmp/shtest before you do. Uncomment to use it. # #exec shelltest /bin/sh /tmp/shtest # Then, # % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.8 # enterprises.ucdavis.extTable.extEntry.extIndex.1 = 1 # enterprises.ucdavis.extTable.extEntry.extIndex.2 = 2 # enterprises.ucdavis.extTable.extEntry.extNames.1 = "echotest" # enterprises.ucdavis.extTable.extEntry.extNames.2 = "shelltest" # enterprises.ucdavis.extTable.extEntry.extCommand.1 = "/bin/echo hello world" # enterprises.ucdavis.extTable.extEntry.extCommand.2 = "/bin/sh /tmp/shtest" # enterprises.ucdavis.extTable.extEntry.extResult.1 = 0 # enterprises.ucdavis.extTable.extEntry.extResult.2 = 35 # enterprises.ucdavis.extTable.extEntry.extOutput.1 = "hello world." # enterprises.ucdavis.extTable.extEntry.extOutput.2 = "hello world." # enterprises.ucdavis.extTable.extEntry.extErrFix.1 = 0 # enterprises.ucdavis.extTable.extEntry.extErrFix.2 = 0 # Note that the second line of the /tmp/shtest shell script is cut # off. Also note that the exit status of 35 was returned. # ----------------------------------------------------------------------------- ############################################################################### # disk checks # # The agent can check the amount of available disk space, and make # sure it is above a set limit. # disk PATH [MIN=100000] # # PATH: mount path to the disk in question. # MIN: Disks with space below this value will have the Mib's errorFlag set. # Default value = 100000. # Check the / partition and make sure it contains at least 10 megs. disk / 10000 # % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.9 # enterprises.ucdavis.diskTable.dskEntry.diskIndex.1 = 0 # enterprises.ucdavis.diskTable.dskEntry.diskPath.1 = "/" Hex: 2F # enterprises.ucdavis.diskTable.dskEntry.diskDevice.1 = "/dev/dsk/c201d6s0" # enterprises.ucdavis.diskTable.dskEntry.diskMinimum.1 = 10000 # enterprises.ucdavis.diskTable.dskEntry.diskTotal.1 = 837130 # enterprises.ucdavis.diskTable.dskEntry.diskAvail.1 = 316325 # enterprises.ucdavis.diskTable.dskEntry.diskUsed.1 = 437092 # enterprises.ucdavis.diskTable.dskEntry.diskPercent.1 = 58 # enterprises.ucdavis.diskTable.dskEntry.diskErrorFlag.1 = 0 # enterprises.ucdavis.diskTable.dskEntry.diskErrorMsg.1 = "" # ----------------------------------------------------------------------------- ############################################################################### # load average checks # # load [1MAX=12.0] [5MAX=12.0] [15MAX=12.0] # # 1MAX: If the 1 minute load average is above this limit at query # time, the errorFlag will be set. # 5MAX: Similar, but for 5 min average. # 15MAX: Similar, but for 15 min average. # Check for loads: load 12 14 14 # % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.10 # enterprises.ucdavis.loadTable.laEntry.loadaveIndex.1 = 1 # enterprises.ucdavis.loadTable.laEntry.loadaveIndex.2 = 2 # enterprises.ucdavis.loadTable.laEntry.loadaveIndex.3 = 3 # enterprises.ucdavis.loadTable.laEntry.loadaveNames.1 = "Load-1" # enterprises.ucdavis.loadTable.laEntry.loadaveNames.2 = "Load-5" # enterprises.ucdavis.loadTable.laEntry.loadaveNames.3 = "Load-15" # enterprises.ucdavis.loadTable.laEntry.loadaveLoad.1 = "0.49" Hex: 30 2E 34 39 # enterprises.ucdavis.loadTable.laEntry.loadaveLoad.2 = "0.31" Hex: 30 2E 33 31 # enterprises.ucdavis.loadTable.laEntry.loadaveLoad.3 = "0.26" Hex: 30 2E 32 36 # enterprises.ucdavis.loadTable.laEntry.loadaveConfig.1 = "12.00" # enterprises.ucdavis.loadTable.laEntry.loadaveConfig.2 = "14.00" # enterprises.ucdavis.loadTable.laEntry.loadaveConfig.3 = "14.00" # enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.1 = 0 # enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.2 = 0 # enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.3 = 0 # enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.1 = "" # enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.2 = "" # enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.3 = "" # ----------------------------------------------------------------------------- ############################################################################### # Extensible sections. # # This alleviates the multiple line output problem found in the # previous executable mib by placing each mib in its own mib table: # Run a shell script containing: # # #!/bin/sh # echo hello world # echo hi there # exit 35 # # Note: this has been specifically commented out to prevent # accidental security holes due to someone else on your system writing # a /tmp/shtest before you do. Uncomment to use it. # # exec .1.3.6.1.4.1.2021.50 shelltest /bin/sh /tmp/shtest # % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.50 # enterprises.ucdavis.50.1.1 = 1 # enterprises.ucdavis.50.2.1 = "shelltest" # enterprises.ucdavis.50.3.1 = "/bin/sh /tmp/shtest" # enterprises.ucdavis.50.100.1 = 35 # enterprises.ucdavis.50.101.1 = "hello world." # enterprises.ucdavis.50.101.2 = "hi there." # enterprises.ucdavis.50.102.1 = 0 # Now the Output has grown to two lines, and we can see the 'hi # there.' output as the second line from our shell script. # # Note that you must alter the mib.txt file to be correct if you want # the .50.* outputs above to change to reasonable text descriptions. # Other ideas: # # exec .1.3.6.1.4.1.2021.51 ps /bin/ps # exec .1.3.6.1.4.1.2021.52 top /usr/local/bin/top # exec .1.3.6.1.4.1.2021.53 mailq /usr/bin/mailq # ----------------------------------------------------------------------------- ############################################################################### # Pass through control. # # Usage: # pass MIBOID EXEC-COMMAND # # This will pass total control of the mib underneath the MIBOID # portion of the mib to the EXEC-COMMAND. # # Note: You'll have to change the path of the passtest script to your # source directory or install it in the given location. # # Example: (see the script for details) # (commented out here since it requires that you place the # script in the right location. (its not installed by default)) # pass .1.3.6.1.4.1.2021.255 /bin/sh /usr/local/local/passtest # % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.255 # enterprises.ucdavis.255.1 = "life the universe and everything" # enterprises.ucdavis.255.2.1 = 42 # enterprises.ucdavis.255.2.2 = OID: 42.42.42 # enterprises.ucdavis.255.3 = Timeticks: (363136200) 42 days, 0:42:42 # enterprises.ucdavis.255.4 = IpAddress: 127.0.0.1 # enterprises.ucdavis.255.5 = 42 # enterprises.ucdavis.255.6 = Gauge: 42 # # % snmpget -v 1 localhost public .1.3.6.1.4.1.2021.255.5 # enterprises.ucdavis.255.5 = 42 # # % snmpset -v 1 localhost public .1.3.6.1.4.1.2021.255.1 s "New string" # enterprises.ucdavis.255.1 = "New string" # # For specific usage information, see the man/snmpd.conf.5 manual page # as well as the local/passtest script used in the above example. ############################################################################### # Further Information # # See the snmpd.conf manual page, and the output of "snmpd -H".
Linux消息队列使用时,msgsnd()一直不能通过,大家帮忙看看!
#include<stdio.h> #include<sys/msg.h> #include<sys/ipc.h> #include<sys/types.h> #include<string.h> #include<errno.h> #include<stdlib.h> #include<unistd.h> #define QUEUE1 100 #define QUEUE2 101 /* * redefine struct msg_buf */ struct msgmbuf{ //msg type long mtype; //the field used to store URL char mtext[256]; }; int main() { /* * create mesage queue!!! */ key_t key; //create msg_queue int msg_flags; //msg is int msg_id1; msg_flags = IPC_CREAT|IPC_EXCL; msg_id1 = msgget((key_t)1111, msg_flags|0x0666); if(-1 == msg_id1){ printf("create msg_queue failed"); return -1; } /* * send mesage */ int msg_sflags; struct msgmbuf msg_mbuf; msg_sflags = IPC_NOWAIT; msg_mbuf.mtype = QUEUE1; char *url1 = "www.baidu.com"; strcpy(msg_mbuf.mtext, url1); printf("%s\n", msg_mbuf.mtext); printf("%ld\n", msg_mbuf.mtype); int ret = msgsnd(msg_id1, &msg_mbuf, 256, msg_sflags); if(-1 == ret){ printf("send msg failed,errno = %d,%s\n",errno,strerrno(errno)); msgctl(msg_id1, IPC_RMID, NULL); exit(1); } /* * receive mesage */ int msg_rflags; msg_rflags = IPC_NOWAIT|MSG_NOERROR; struct msgmbuf msg_rev; ret = msgrcv(msg_id1, &msg_rev, sizeof(struct msgmbuf), QUEUE1, msg_rflags); if(-1 == ret){ printf("receive msg failed\n"); msgctl(msg_id1, IPC_RMID, NULL); return -1; }else{ printf("mtext: %s\n", msg_rev.mtext); printf("mtype: %ld\n", msg_rev.mtype); } msgctl(msg_id1, IPC_RMID, NULL); return 0; }
关于linux下fork创建进程的问题
本意是希望通过父进程创建两个进程,但是不知道为什么不停创建client,代码如下,希望有时间的帮忙看一下,十分感谢! #include<iostream> #include <string.h> #include<fstream> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/stat.h> #include <sys/msg.h> #define PERM S_IRUSR|S_IWUSR #define MSG_FILE "/home/allen/myfiles/server.c" using namespace std; class msgtype{ public: long msgtyoe; char buffer[256]; }; //a judge function for clien son process bool judge(char *); int main() { int msgid;//message queue id. //use global variable ,evety child thread can get the message queue key. //msgtype msg; key_t key; if(pid_t fpid=fork()>=0) { // server child thread code block if(fpid==0) { //server code block //it is the child thread cout<<"this is server thread"<<endl; //create file stream to save the key or save msgid. ofstream msgfile(MSG_FILE); msgtype *msg=new msgtype; if ((msgid = msgget(key, PERM | IPC_CREAT | IPC_EXCL)) == -1) { fprintf(stderr, "Creat Message Error:%s\a\n", strerror(errno)); exit(1); } else { msgfile<<msgid; msgfile.close(); //output the msgid for debug. cout<<msgid<<endl; while(1) { int x; cin >> x; //do not check the type and return the oldest msg autolly. msgrcv(msgid,msg,sizeof(msgtype),1,0); if(msg->buffer[0]!='j') { cout<<"Server Receive :"<<msg->buffer<<endl; } else if (msg->buffer[0]=='s') { exit(0); } else { msg->msgtyoe=2; string h="j"+110; memcpy(msg->buffer,h.c_str(),sizeof(h.c_str())); msgsnd(msgid,msg,sizeof(msgtype),0); } } } } //parent thread block else { pid_t client_thread; msgtype *msg=new msgtype; if(client_thread=fork()==-1) { fprintf(stderr,"Create client thread error: %s\a\n",strerror(errno)); exit(1); } else{ //client child thread code block if(client_thread==0) { ifstream inmsgfile("MSG_FILE"); cout<<"this is client thread"<<endl; if(msgid=msgget(key,PERM)!=-1) { msg->msgtyoe=1; inmsgfile >> msgid; cout<<"msgid == "<<msgid<<endl; msgsnd(msgid,msg,sizeof(msgtype),0); msgrcv(msgid,msg,sizeof(msgtype),2,0); if(judge(msg->buffer)) { string h="it is a prime "+msg->buffer[1]; memcpy(msg->buffer,h.c_str(),sizeof(h.c_str())); msgsnd(msgid,msg,sizeof(msgtype),0); } exit(0); } } } } } cout << "Hello world!" << endl; return 0; } bool judge(char *s) { if(s[0]=='j')//first j means to judge { int n=s[1]; if ( n < 2 ) { // 小于2的数即不是合数也不是素数 throw 0; } static unsigned aPrimeList[] = { // 素数表 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 113, 193, 241, 257, 337, 353, 401, 433, 449, 577, 593, 641, 673, 769, 881, 929, 977, 1009, 1153, 1201, 1217, 1249, 1297,1361, 1409, 1489, 1553, 1601, 1697, 1777, 1873, 1889, 2017, 2081, 2113, 2129, 2161, 2273, 2417, 2593, 2609, 2657, 2689, 2753, 2801, 2833, 2897, 3041, 3089, 3121, 3137, 3169, 3217, 3313, 3329, 3361, 3457, 3617, 3697, 3761, 3793, 3889, 4001, 4049, 4129, 4177, 4241, 4273, 4289, 4337, 4481, 4513, 4561, 4657, 4673, 4721, 4801, 4817, 4993, 5009, 5153, 5233, 5281, 5297, 5393, 5441, 5521, 5569, 5857, 5953, 6113, 6257, 6337, 6353, 6449, 6481, 6529, 6577, 6673, 6689, 6737, 6833, 6961, 6977, 7057, 7121, 7297, 7393, 7457, 7489, 7537, 7649, 7681, 7793, 7841, 7873, 7937, 8017, 8081, 8161, 8209, 8273, 8353, 8369, 8513, 8609, 8641, 8689, 8737, 8753, 8849, 8929, 9041, 9137, 9281, 9377, 9473, 9521, 9601, 9649, 9697, 9857 }; const int nListNum = sizeof(aPrimeList)/sizeof(unsigned);//计算素数表里元素的个数 for (unsigned i=2;i<nListNum;++i ) { if(n/2+1<aPrimeList[i]) { return true; } if(0==n%aPrimeList[i]) { return false; } } /*由于素数表中元素个数是有限的,那么对于用素数表判断不到的数,就只有用笨蛋办法了*/ for (unsigned i=aPrimeList[nListNum-1];i<n/2+1;i++ ) { if (0==n%i) { // 除尽了,合数 return false; } } return true; } } 输出如下: /home/allen/.CLion2016.2/system/cmake/generated/process_msg_clion-b927b03f/b927b03f/Debug/proess_msg this is client thread this is client thread Hello world! this is client thread Hello world! Hello world! this is client thread Hello world! Process finished with exit code 0 IDE用的是CLION
相见恨晚的超实用网站
搞学习 知乎:www.zhihu.com 简答题:http://www.jiandati.com/ 网易公开课:https://open.163.com/ted/ 网易云课堂:https://study.163.com/ 中国大学MOOC:www.icourse163.org 网易云课堂:study.163.com 哔哩哔哩弹幕网:www.bilibili.com 我要自学网:www.51zxw
花了20分钟,给女朋友们写了一个web版群聊程序
参考博客 [1]https://www.byteslounge.com/tutorials/java-ee-html5-websocket-example
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
引言 本文主要是记录一下面试字节跳动的经历。 三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时
开源一个功能完整的SpringBoot项目框架
福利来了,给大家带来一个福利。 最近想了解一下有关Spring Boot的开源项目,看了很多开源的框架,大多是一些demo或者是一个未成形的项目,基本功能都不完整,尤其是用户权限和菜单方面几乎没有完整的。 想到我之前做的框架,里面通用模块有:用户模块,权限模块,菜单模块,功能模块也齐全了,每一个功能都是完整的。 打算把这个框架分享出来,供大家使用和学习。 为什么用框架? 框架可以学习整体
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
Python——画一棵漂亮的樱花树(不同种樱花+玫瑰+圣诞树喔)
最近翻到一篇知乎,上面有不少用Python(大多是turtle库)绘制的树图,感觉很漂亮,我整理了一下,挑了一些我觉得不错的代码分享给大家(这些我都测试过,确实可以生成喔~) one 樱花树 动态生成樱花 效果图(这个是动态的): 实现代码 import turtle as T import random import time # 画樱花的躯干(60,t) def Tree(branch
深深的码丨Java HashMap 透析
HashMap 相关概念 HashTab、HashMap、TreeMap 均以键值对像是存储或操作数据元素。HashTab继承自Dictionary,HashMap、TreeMap继承自AbstractMap,三者均实现Map接口 **HashTab:**同步哈希表,不支持null键或值,因为同步导致性能影响,很少被使用 **HashMap:**应用较多的非同步哈希表,支持null键或值,是键值对...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
JDK12 Collectors.teeing 你真的需要了解一下
前言 在 Java 12 里面有个非常好用但在官方 JEP 没有公布的功能,因为它只是 Collector 中的一个小改动,它的作用是 merge 两个 collector 的结果,这句话显得很抽象,老规矩,我们先来看个图(这真是一个不和谐的图????): 管道改造经常会用这个小东西,通常我们叫它「三通」,它的主要作用就是将 downstream1 和 downstre...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1...
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员...
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC...
8年经验面试官详解 Java 面试秘诀
作者 |胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。 Java程序员准备和投递简历的实...
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车?某胡同口的煎饼摊一年能卖出多少个煎饼?深圳有多少个产品经理?一辆公交车里能装下多少个乒乓球?一个正常成年人有多少根头发?这类估算问题,被称为费米问题,是以科学家费米命名的。为什么面试会问这种问题呢?这类问题能把两类人清楚地区分出来。一类是具有文科思维的人,擅长赞叹和模糊想象,它主要依靠的是人的第一反应和直觉,比如小孩...
相关热词 c# clr dll c# 如何orm c# 固定大小的字符数组 c#框架设计 c# 删除数据库 c# 中文文字 图片转 c# 成员属性 接口 c#如何将程序封装 16进制负数转换 c# c#练手项目
立即提问