posts - 27,comments - 2,trackbacks - 0
          做個(gè)總結(jié)
          linux服務(wù)器上做負(fù)載均衡
          自己準(zhǔn)備的:linux服務(wù)器(45.78.20.168),jdk1.7,nginx,redis,tomcat7兩個(gè),部署的項(xiàng)目;

          1:jdk1.7安裝,兩個(gè)tomcat分別端口8080,8081;部署相同的項(xiàng)目;啟動(dòng);
              http://45.78.20.168:8080/redis3.2/getRedis.action
              http://45.78.20.168:8081/redis3.2/getRedis.action
          2:安裝nginx,添加負(fù)載的配置,安裝目錄下找 /etc/nginx/conf.d/default.conf文件(或/etc/nginx/nginx.conf);策略設(shè)置為默認(rèn)輪詢;
              upstream www.nimenhaihaoma.com {
                  server 45.78.20.168:8080;
                  server 45.78.20.168:8081;
              }
              server{
                  listen 80;
                  server_name www.nimenhaihaoma.com;
                  location / {
                      proxy_pass http://www.nimenhaihaoma.com;
                      proxy_set_header Host $host;
                      proxy_set_header X-Real-IP $remote_addr;
                      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  }
          3:配置session共享,方式很多,這里用的redis的session共享(兼容jdk版本至少1.7):
              tomcat的lib包加commons-pool2-2.0.jar,jedis-2.5.2.jar,tomcat-redis-session-manager1.2.jar;
              tomcat配置文件context.xml,在標(biāo)簽<Context>內(nèi)添加配置:
                  <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
                  <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="localhost" port="6379" database="0" maxInactiveInterval="60" />

          4:項(xiàng)目里面區(qū)分session的代碼:
              (1):放session的接口(執(zhí)行一次);
              (2):取session數(shù)據(jù)(不斷刷新),看tomcat打印信息;
          5:效果,http://www.nimenhaihaoma.com/redis3.2/getRedis.action (狂刷session值相同)



          posted @ 2016-08-17 17:03 魏文甫 閱讀(126) | 評(píng)論 (0)編輯 收藏
          項(xiàng)目只是加載spring的幾個(gè)定時(shí)任務(wù),啟動(dòng)服務(wù)一直循環(huán)加載spring文件,問(wèn)題的根節(jié)點(diǎn):定時(shí)器類里面的service對(duì)象采取配置的方式注入,而這個(gè)定時(shí)器類的構(gòu)造讓我給加上了:
          ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext*.xml");
          myServiceImpl = context.getBean("XXXService");

          加上這段為了方便測(cè)試,在該類里寫(xiě)main方法測(cè)試執(zhí)行,把調(diào)用寫(xiě)到構(gòu)造里;,spring定時(shí)器配置好時(shí)間后,此處構(gòu)造忘了去掉;導(dǎo)致啟動(dòng)tomcat服務(wù)一直在加載spring注入文件;
          同理,spring注入的方式,在action里同樣有這樣的效果,構(gòu)造方法一定注意;
          posted @ 2015-04-25 11:09 魏文甫 閱讀(182) | 評(píng)論 (0)編輯 收藏
          是在build.xml編譯的時(shí)候,包里有兩個(gè)類名一樣的java文件,我只是做了個(gè)備份,忘了改文件后綴,備份的文件也編譯了,所以報(bào)的這個(gè)錯(cuò)
          posted @ 2014-08-28 20:18 魏文甫 閱讀(845) | 評(píng)論 (0)編輯 收藏
          1,添加索引文件中的一條新的索引     
                          Question addQ = new Question();//新添加的一條數(shù)據(jù),對(duì)象id在索引文件中沒(méi)有
                          addQ.setId("999999999");
                          addQ.setQuestionname("新添加的一條數(shù)據(jù)名稱");
                          Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
          IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
          iwc.setOpenMode(OpenMode.APPEND);
          IndexWriter writer = null;
          try {
          Directory dir1 = FSDirectory.open(new File("F:\\temp"));
          writer = new IndexWriter(dir1, iwc);
          FieldType ft = new FieldType();
          ft.setIndexed(true);
          ft.setStored(true);
          ft.setTokenized(true);
          FieldType ft2 = new FieldType();
          ft2.setIndexed(true);
          ft2.setStored(true);
          ft2.setTokenized(false);
          Document doc = new Document();
          doc.add(new Field("id", addQ.getId(), ft2));
          doc.add(new Field("questionname", addQ.getQuestionname(), ft));
          writer.addDocument(doc);
          writer.close();
          } catch (CorruptIndexException e) {
          e.printStackTrace();
          } catch (LockObtainFailedException e) {
          e.printStackTrace();
          } catch (IOException e) {
          e.printStackTrace();
          } finally{
          try {
          if(writer!=null){
          writer.close();
          }
          if(sa!=null){
          sa.close();
          }
          } catch (CorruptIndexException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          }
          }
          執(zhí)行完程序后,索引文件中已經(jīng)添加新的索引數(shù)據(jù)。
          2,刪除索引文件中的一條新的索引
                          Question delQ = new Question();//索引文件中有的一條數(shù)據(jù),根據(jù)對(duì)象id刪
                          delQ.setId("1111111");
                          delQ.setQuestionname("要?jiǎng)h除的一條數(shù)據(jù)");
                          IndexWriter writer = null;
          Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
          IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
          Directory dir1 = null;
          try {
          dir1 = FSDirectory.open(new File("F:\\temp"));
          writer = new IndexWriter(dir1, iwc);
          Term term = new Term("id", delQ.getId());
          writer.deleteDocuments(term);
          writer.commit();
          writer.close();
          } catch (CorruptIndexException e) {
          e.printStackTrace();
          } catch (LockObtainFailedException e) {
          e.printStackTrace();
          } catch (IOException e) {
          e.printStackTrace();
          } finally {
          try {
          if (writer != null) {
          writer.close();
          sa.close();
          }
          } catch (CorruptIndexException e) {
          e.printStackTrace();
          } catch (IOException e) {
          e.printStackTrace();
          }
          }
          System.out.println("索引刪除完成");
          3,更新索引文件中的一條索引
          更新索引文件中的一條索引的理念是:先找到這條索引刪除,然后再添加這條更新后的索引


          posted @ 2013-08-16 12:08 魏文甫 閱讀(346) | 評(píng)論 (0)編輯 收藏
                          IndexReader reader = DirectoryReader.open(FSDirectory.open(new File("F:\\temp")));// 打開(kāi)索引
          IndexSearcher searcher = new IndexSearcher(reader);
          Analyzer analyzer = new SmartChineseAnalyzer(Version.LUCENE_40);
          String[] fields = { "questionname","id" };
          Occur[] occurs = new Occur[] { Occur.SHOULD,Occur.SHOULD };
          Query query =  MultiFieldQueryParser.parse(Version.LUCENE_40, "測(cè)試 的", fields,
          occurs, analyzer);
          TopDocs result = searcher.search(query, searcher.getIndexReader()
          .maxDoc());
          ScoreDoc[] hits = result.scoreDocs;
          List<Document> list = new ArrayList<Document>();
          for (int i = 0; i <hits.length; i++) {
          Document doc = searcher.doc(hits[i].doc);
          list.add(doc);
          }
          System.out.println("搜索list的長(zhǎng)度\t→→→→\t"+list.size());
          for (Document document : list) {
          System.out.println(document.getField("questionname"));
          }
          analyzer.close();

          注:紅色字體是輸入的檢索條件,多個(gè)用空格隔開(kāi),找到的結(jié)果先匹配同時(shí)符合多個(gè)的結(jié)果,結(jié)果只是拿過(guò)來(lái)的document一個(gè)list集合,具體結(jié)果再解析就行了。

          結(jié)果如圖:
          posted @ 2013-08-12 17:26 魏文甫 閱讀(1181) | 評(píng)論 (1)編輯 收藏
                          Connection conn = null;
          Statement stat = null;
          ResultSet rs = null;
          Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
          IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
          iwc.setOpenMode(OpenMode.CREATE);
          Directory dir1 = FSDirectory.open(new File("F:\\temp"));
          IndexWriter writer = new IndexWriter(dir1, iwc);
          int numIndexed = -1;
          FieldType ft = new FieldType();
          ft.setIndexed(true);
          ft.setStored(true);
          ft.setTokenized(true);
          FieldType ft2 = new FieldType();
          ft2.setIndexed(true);
          ft2.setStored(true);
          ft2.setTokenized(false);
          Class.forName("com.mysql.jdbc.Driver");
          conn = (Connection) DriverManager.getConnection(
          "jdbc:mysql:///question", "root", "root");
          stat = (Statement) conn.createStatement();
          rs = stat.executeQuery("select id,questionname from question");
          List<String> list = new ArrayList<String>();
          while (rs.next()) {
          String id = rs.getString("questionname");
          String questionname = rs.getString("questionname");
          list.add(id);
          list.add(questionname);
          }
          rs.close();
          stat.close();
          conn.close();
          for (String string : list) {
          Document doc = new Document();
          doc.add(new Field("questionname", string, ft2));
          writer.addDocument(doc);
          }
          numIndexed = writer.maxDoc();
          writer.close();
          執(zhí)行完這段程序f盤(pán)多一個(gè)文件夾temp,里面就是創(chuàng)建好的索引文件了,然后進(jìn)行根據(jù)索引文件查詢
          posted @ 2013-08-12 16:50 魏文甫 閱讀(1421) | 評(píng)論 (0)編輯 收藏
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
          <head>
          <meta http-equiv="Content-Type" content="text/html;charset=GBK" />
          <title></title>
          <script type="text/javascript" src="jquery-1.8.2.js"></script>
          <script type="text/javascript">
          $(document).mousemove(function(e) {
          var innerHeight = window.innerHeight;
          if (e.pageY > innerHeight) {
          $("#topDiv").css("display", "block");
          }
          if (e.pageY < innerHeight) {
          $("#topDiv").css("display", "none");
          }
          });
          $("#topIcon").mouseover(function() {
          $("#topIcon").css("text-decoration", "none");
          $("#topIcon").children("i").removeClass();
          $("#topIcon").children("i").addClass("icon-chevron-up");
          });
          $("#topIcon").mouseout(function() {
          $("#topIcon").children("i").removeClass();
          $("#topIcon").children("i").addClass("icon-arrow-up");
          });
          </script>
          </head>
          <body id="bodyId">
          <div id="topDiv"
          style="position: fixed;right: 60px;bottom: 60px;display: none">
          <a id="topIcon" href="#bodyId" style="background-color: #aaaaaa"><span
          style="text-align: justify;display: block;text-decoration: none;width: 14px;background-color: #cccccc">回到頂端</span>
          </a>
          </div>
          <h1>O(∩_∩)O哈哈~</h1>
          <h2>(*^__^*) 嘻嘻……</h2>
          <h3>O(∩_∩)O~</h3>
          <h4>\(^o^)/~</h4>
          <h5>$_$</h5>
          <h6>o(╯□╰)o</h6>
          <h1>O(∩_∩)O哈哈~</h1>
          <h2>(*^__^*) 嘻嘻……</h2>
          <h3>O(∩_∩)O~</h3>
          <h4>\(^o^)/~</h4>
          <h5>$_$</h5>
          <h6>o(╯□╰)o</h6>
          <h1>O(∩_∩)O哈哈~</h1>
          <h2>(*^__^*) 嘻嘻……</h2>
          <h3>O(∩_∩)O~</h3>
          <h4>\(^o^)/~</h4>
          <h5>$_$</h5>
          <h6>o(╯□╰)o</h6>
          <h1>O(∩_∩)O哈哈~</h1>
          <h2>(*^__^*) 嘻嘻……</h2>
          <h3>O(∩_∩)O~</h3>
          <h4>\(^o^)/~</h4>
          <h5>$_$</h5>
          <h6>o(╯□╰)o</h6>
          <h1>O(∩_∩)O哈哈~</h1>
          <h2>(*^__^*) 嘻嘻……</h2>
          <h3>O(∩_∩)O~</h3>
          <h4>\(^o^)/~</h4>
          <h5>$_$</h5>
          <h6>o(╯□╰)o</h6>
          <h1>O(∩_∩)O哈哈~</h1>
          <h2>(*^__^*) 嘻嘻……</h2>
          <h3>O(∩_∩)O~</h3>
          <h4>\(^o^)/~</h4>
          <h5>$_$</h5>
          <h6>o(╯□╰)o</h6>
          <h1>O(∩_∩)O哈哈~</h1>
          <h2>(*^__^*) 嘻嘻……</h2>
          <h3>O(∩_∩)O~</h3>
          <h4>\(^o^)/~</h4>
          <h5>$_$</h5>
          <h6>o(╯□╰)o</h6>
          <h1>O(∩_∩)O哈哈~</h1>
          <h2>(*^__^*) 嘻嘻……</h2>
          <h3>O(∩_∩)O~</h3>
          <h4>\(^o^)/~</h4>
          <h5>$_$</h5>
          <h6>o(╯□╰)o</h6>
          </body>
          </html>
          posted @ 2013-08-07 10:35 魏文甫 閱讀(216) | 評(píng)論 (0)編輯 收藏
          求單一登陸和單點(diǎn)登陸的思路及核心代碼???
          posted @ 2013-08-07 09:56 魏文甫 閱讀(330) | 評(píng)論 (0)編輯 收藏
          html中中文正則表達(dá)式不對(duì)的問(wèn)題 
          中文的正則表達(dá)式:var reg = /^[\u4e00-\u9fa5]$/;(一個(gè)中文字符)
          放在html中可能出現(xiàn)的問(wèn)題有:
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
          <head>
          <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
          <title></title>
          </head>
          <body>
          <script type="text/javascript">
                      var reg0 = /^[\u4e00-\u9fa5]$/;
                      alert(reg0.test("看"));
          </script>
          </body>
          </html>
          本頁(yè)編碼為UTF-8時(shí)出現(xiàn)的結(jié)果可能是錯(cuò)誤的,
          所以出現(xiàn)此類情況,編碼格式改為gb2312(紅色標(biāo)注的編碼改為gb2312)
          posted @ 2013-07-29 15:56 魏文甫 閱讀(227) | 評(píng)論 (0)編輯 收藏
          簡(jiǎn)單的代碼:
          public static void main(String[] args) {
          try {
          File allfile = new File("f:\\excel\\total.xlsx");
          File file2 = new File("f:\\excel\\xxxxxx.xlsx");
          XSSFWorkbook h = new XSSFWorkbook(new FileInputStream(allfile));
          XSSFSheet x = h.getSheetAt(0);
          XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream(file2));
          XSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0);
          int ii = hssfSheet.getLastRowNum();//讀取的表格行數(shù)
          System.out.println(ii);
          FileOutputStream out_ = new FileOutputStream(allfile);
          for (int i = 0; i < ii; i++) {
          XSSFRow lastRow = x.createRow(x.getLastRowNum()+1);
          XSSFRow xssfRow = hssfSheet.getRow(i);
          XSSFCell xssfCell0 = xssfRow.getCell(0);
          CellStyle cellStyle0 = xssfCell0.getCellStyle();
          CellStyle newStyle0 = h.createCellStyle();
          newStyle0.cloneStyleFrom(cellStyle0);
          XSSFCell xssfCell0_ = lastRow.createCell(0);
          xssfCell0_.setCellStyle(newStyle0);
          xssfCell0_.setCellValue(xssfCell0.toString());
          XSSFCell xssfCell1 = xssfRow.getCell(1);
          CellStyle cellStyle1 = xssfCell1.getCellStyle();
          CellStyle newStyle1 = h.createCellStyle();
          newStyle1.cloneStyleFrom(cellStyle1);
          XSSFCell xssfCell1_ = lastRow.createCell(1);
          xssfCell1_.setCellStyle(newStyle1);
          xssfCell1_.setCellValue(xssfCell1.toString());
          XSSFCell xssfCell2 = xssfRow.getCell(2);
          CellStyle cellStyle2 = xssfCell2.getCellStyle();
          CellStyle newStyle2 = h.createCellStyle();
          newStyle2.cloneStyleFrom(cellStyle2);
          XSSFCell xssfCell2_ = lastRow.createCell(2);
          xssfCell2_.setCellStyle(newStyle2);
          xssfCell2_.setCellValue(xssfCell2.toString());
          XSSFCell xssfCell3 = xssfRow.getCell(3);
          CellStyle cellStyle3 = xssfCell3.getCellStyle();
          CellStyle newStyle3 = h.createCellStyle();
          newStyle3.cloneStyleFrom(cellStyle3);
          XSSFCell xssfCell3_ = lastRow.createCell(3);
          xssfCell3_.setCellStyle(newStyle3);
          xssfCell3_.setCellValue(xssfCell3.toString());
          XSSFCell xssfCell4 = xssfRow.getCell(4);
          CellStyle cellStyle4 = xssfCell4.getCellStyle();
          CellStyle newStyle4 = h.createCellStyle();
          newStyle4.cloneStyleFrom(cellStyle4);
          XSSFCell xssfCell4_ = lastRow.createCell(4);
          xssfCell4_.setCellStyle(newStyle4);
          xssfCell4_.setCellValue(xssfCell4.toString().toString());
          }
          h.write(out_);
          out_.flush();
          out_.close();
          } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          }
          }
          posted @ 2013-07-19 18:02 魏文甫 閱讀(639) | 評(píng)論 (0)編輯 收藏
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
          <head>
          <meta http-equiv="Content-Type" content="text/html;charset=GBK" />
          <title></title>
          </head>
          <body>
          <h1>提示離開(kāi)當(dāng)前頁(yè)面的js代碼</h1>
          <a >百度鏈接</a>
          <script type="text/javascript">
          if (window != top) {
          top.location.href = "login.action";
          } else {
          if (window.Event) {
          window.onbeforeunload = function(event) {
          return "你是否要離開(kāi)此頁(yè)面,離開(kāi)此頁(yè)面信息將不被保存!";
          };
          } else {
          window.onbeforeunload = function() {
          return "你是否要離開(kāi)此頁(yè)面,離開(kāi)此頁(yè)面信息將不被保存!";
          };
          }
          }
          </script>
          </body>
          </html>
          posted @ 2013-07-18 15:04 魏文甫 閱讀(247) | 評(píng)論 (0)編輯 收藏
          主站蜘蛛池模板: 沂南县| 三江| 景泰县| 封开县| 玛曲县| 孟津县| 乌兰浩特市| 长春市| 巩留县| 休宁县| 和林格尔县| 太原市| 百色市| 汕头市| 佛山市| 海门市| 洪洞县| 高邑县| 隆昌县| 兰考县| 南宫市| 安康市| 乐业县| 岢岚县| 忻城县| 共和县| 卫辉市| 兴安盟| 龙里县| 饶河县| 陇南市| 桦川县| 梅河口市| 曲麻莱县| 抚顺县| 灵宝市| 绥棱县| 赣榆县| 永川市| 洪湖市| 循化|