程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> 用java等說話仿360首頁拼音輸出全隱約搜刮和主動換膚

用java等說話仿360首頁拼音輸出全隱約搜刮和主動換膚

編輯:關於JAVA

用java等說話仿360首頁拼音輸出全隱約搜刮和主動換膚。本站提示廣大學習愛好者:(用java等說話仿360首頁拼音輸出全隱約搜刮和主動換膚)文章只能為提供參考,不一定能成為您想要的結果。以下是用java等說話仿360首頁拼音輸出全隱約搜刮和主動換膚正文


360首頁搜刮後果以下


1、完成編寫的schoolnet校園網重要目次構造以下


重要完成支撐中文、拼音首字母、拼音全字母的智能搜刮和換膚

頁面後果以下



重要焦點代碼以下

1、head.jsp

<%@page import="java.io.File"%> 
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
<title>校園網首頁面</title> 
<link rel="stylesheet" href="/schoolnet/css/index.css" type="text/css" /> 
<script type="text/javascript" src="/schoolnet/js/ddsmoothmenu.js"></script> 
<script src="/schoolnet/js/jquery.js"></script> 
<script src="/schoolnet/js/jquery-ui.js"></script> 
<script type="text/javascript" src="/schoolnet/js/publicJs.js"></script> 
<script type="text/javascript" src="/schoolnet/myAJAX/ajax_uni.js"></script> 
<script type="text/javascript" src="/schoolnet/js/style.js"></script> 
<c:if test="${loginuser.skin.id!=null }"> 
 <script type="text/javascript"> 
  $(document).ready( 
 
    function setskin() { 
     var photo = '${loginuser.skin.photo}'; 
     $("body").css( 
       "background", 
       "#f6f6f6 url(/schoolnet/images/pf/" + photo 
         + ") top repeat"); 
    }); 
 </script> 
 
 
</c:if> 
</head> 
<body> 
 <div class="topsearch"> 
  <div class="topsearchtype" id="searchtype"> 
   <a class="current" href="javascript:void(0)" 
    onclick="setsearchtype(this),setsearch()" name="searchdatas" 
    id="books.png">材料</a> <a href="javascript:void(0)" 
    onclick="setsearchtype(this),setsearch()" name="searchsongs" 
    id="t01d566d0c28b32ddad.png">音樂</a> <a href="javascript:void(0)" 
    onclick="setsearchtype(this),setsearch()" name="searchnews" 
    id="newspaper.png">消息</a> <a href="javascript:void(0)" 
    onclick="setsearchtype(this),setsearch()" name="searchxiaoshuos" 
    id="library.png">小說</a> <a href="javascript:void(0)" 
    onclick="setsearchtype(this),setsearch()" name="searcharticles" 
    id="blog.gif">日記</a> 
  </div> 
  <form id="search-form" 
   action="/schoolnet/other.do?flag=searchdatas&searchpageNow=1" 
   method="post" name="searchdatas" target="blank" 
   onsubmit="return checksearch()"> 
   <img src="/schoolnet/images/front/books.png" id="searchimg" 
    width="32px" height="32px"  /><input 
    type="text" class="topsearchtext" name="search" id="topsearchtext" 
    onkeyup="setsearch()" onfocus="newsearch()" "/> <input 
    id="inputsearchtype" type="submit" class="topsearchbutton" 
    value="搜刮材料" /> 
  </form> 
  <ul id="setsearch" class="setsearch"> 
  </ul> 
 </div> 
 <div id="MainMenu" class="ddsmoothmenu"> 
  <ul> 
   <li><a href="/schoolnet/login.do?flag=goHomeUI" title="" 
    id="*menu_selected"><span>校園網</span> 
   </a> 
   </li> 
   <li><a href="/schoolnet/login.do?flag=goHomeUI" title=""><span>小我中間</span> 
   </a></li> 
   <li><a href="/schoolnet/profile.do?flag=goHomePageUI" title=""><span>我的主頁</span> 
   </a></li> 
   <li><a href="javascript:void(0)" title=""><span>運用</span> 
   </a> 
   <ul class="menulevel"> 
     <li><a href="/schoolnet/shou.do?flag=ShuoShuo&pageNow=1" 
      title="">說說</a> 
     </li> 
     <li><a 
      href="/schoolnet/album.do?flag=myAlbumUI&pageNow=1&userid=${loginuser.id }" 
      title="">相冊</a> 
     </li> 
     <li><a href="/schoolnet/friend.do?flag=myfriendUI&pageNow=1" 
      title="">石友</a> 
     </li> 
     <li><a 
      href="/schoolnet/article.do?flag=articleUI&pageNow=1&userid=${loginuser.id }" 
      title="">日記</a> 
     </li> 
     <li><a href="/schoolnet/music.do?flag=goMusicHome&pageNow=1" 
      title="">音樂</a> 
     </li> 
     <li><a 
      href="/schoolnet/news.do?flag=gonewsUI&typeid=1&pageNow=1" 
      title="">消息</a> 
     </li> 
     <li><a 
      href="/schoolnet/datas.do?flag=godatasUI&pageNow=1&action=all" 
      title="">材料</a> 
     </li> 
     <li><a 
      href="/schoolnet/xiaoshuo.do?flag=goxiaoshuoUI&pageNow=1&id=all" 
      title="">小說</a> 
     </li> 
     <li><a 
      href="/schoolnet/skin.do?flag=goskinUI&pageNow=1&id=all" title="">打扮</a> 
     </li> 
     <li><a href="/schoolnet/share .do?flag=goShareUI&pageNow=1" 
      title="">新穎事</a> 
     </li> 
    </ul> 
   </li> 
   <li><a href="javascript:void(0)" title=""><span>關於</span> 
   </a> 
   <ul class="menulevel"> 
     <li><a href="/schoolnet/other.do?flag=goAboutUI#1" title="">關於我們</a> 
     </li> 
     <li><a href="/schoolnet/other.do?flag=goAboutUI#2" title="">網站地圖</a> 
     </li> 
     <li><a href="/schoolnet/other.do?flag=goAboutUI#3" title="">版權解釋</a> 
     </li> 
     <li><a href="/schoolnet/other.do?flag=goAboutUI#4" title="">友誼鏈接</a> 
     </li> 
    </ul> 
   </li> 
   <li><a href="javascript:void(0)" title=""><span>設置</span> 
   </a> 
   <ul class="menulevel"> 
     <li><a href="/schoolnet/register.do?flag=updUI">修正小我信息</a> 
     </li> 
     <li><a href="/schoolnet/login.do?flag=logout">加入</a> 
     </li> 
    </ul> 
   </li> 
  </ul> 
  <c:if test="${loginuser!=null }"> 
   <div id="page-wrap"> 
    <ul class="dropdown"> 
     <li id="menu_selected"><a id="menu_selected" 
      href="/schoolnet/login.do?flag=goHomeUI">  <img 
       src="/schoolnet/images/head/${loginuser.photo}" width="120px" 
       height="45px"  /> 
     </a> 
      <ul class="sub_menu"> 
       <li><a href="/schoolnet/register.do?flag=updUI">修正小我信息</a> 
       </li> 
       <li><a href="/schoolnet/login.do?flag=logout">加入</a> 
       </li> 
      </ul></li> 
    </ul> 
   </div> 
  </c:if> 
 </div> 
</body> 
</html> 

2、重要js函數

//用於設置切換搜刮類型,觸發input控件核心時顯示對應的熱點(前五個)內容(材料、音樂、消息、小說、日記) 
function setsearchtype(o){ 
 $("#searchtype a").removeClass("current"); 
 $(o).addClass("current"); 
 var inputsearchtype=$(o).text(); 
 $("#inputsearchtype").val("搜刮"+inputsearchtype); 
 document.getElementById("search-form").action="/schoolnet/other.do?flag="+o.name+"&searchpageNow=1"; 
 document.getElementById("search-form").name=o.name; 
 document.getElementById("searchimg").src="/schoolnet/images/front/"+o.id; 
 $("#topsearchtext").show(); 
 $("#searchfriendss").hide(); 
 if(o.name=="searchfriends") 
  { 
   $("#topsearchtext").hide(); 
   $("#searchfriendss").show(); 
  } 
} 
//用於設置顯示智能提醒的內容(隱約搜刮時婚配的前十個) 
function setsearch() 
{ 
 var v=document.getElementById("topsearchtext").value; 
 var type=document.getElementById("search-form").name; 
 if(v.length==0) 
  { 
  $("#setsearch").html(""); 
  } 
 if(v.length>0) 
 { 
  $.ajax({     
   cache: true,     
   type: "POST",     
   url : "/schoolnet/ChangeInfo",    
   data: {"action":"setsearch","search":v,"searchtype":type}, 
   async: false, 
   dataType: "html", 
   success: function(data) { 
    $("#setsearch").html(""); 
    $("#setsearch").append(data); 
   }  
   }); 
 }; 
} 

重要java文件

if("searchsongs".equals(searchtype)) 
<span >   </span>{ 
<span >    </span>String nameHEAD[]=ChinesePinYinTool.getHeadByString(search); 
<span >    </span>String nameHeadString=""; 
<span >    </span>for (int i = 0; i < nameHEAD.length; i++) { 
<span >     </span>nameHeadString+=nameHEAD[i]; 
<span >    </span>} 
<span >    </span>String nameALL[]=ChinesePinYinTool.stringToPinyin(search); 
<span >    </span>String nameAllString=""; 
<span >    </span>for (int i = 0; i < nameALL.length; i++) { 
<span >     </span>nameAllString+=nameALL[i]; 
<span >    </span>} 
<span >    </span>List<Song> songs=universityService.executeQueryByPage("from Song where to_pinyin(name) like '%"+ nameAllString +"%' or pinyin(name) like '%"+ nameHeadString +"%'", null, 1, 10); 
<span >    </span>for(int i=0;i<songs.size();i++) 
<span >    </span>{ 
<span >     </span>con +="<li><a target='blank' href='/schoolnet/music.do?flag=goPatentDisplay&pid="+songs.get(i).getPatent().getId()+"'>"+songs.get(i).getName()+"</a></li>"; 
<span >    </span>} 
<span >    </span>if (songs.size()!=0) { 
<span >     </span>con +="<li><a href='javascript:void(0)' onclick='hideli()' style='display:inline;float:right;margin-right:8px;'>封閉</a></li>"; 
<span >    </span>} 
<span >    </span>else { 
<span >     </span>con +="<li><a href='javascript:void(0)' onclick='hideli()' style='display:inline;'>無隨意率性婚配成果</a></li>"; 
<span >    </span>} 
<span >    </span>out.write(con); 
<span >    </span>out.close(); 
<span >   </span>} 
else if("setpifu".equals(action)) 
<span >  </span>{ 
<span >   </span>String skinid=request.getParameter("skinid"); 
<span >   </span>Skin skin=(Skin) universityService.findById(Skin.class, Integer.valueOf(skinid)); 
<span >   </span>Users user=(Users) request.getSession().getAttribute("loginuser"); 
<span >   </span>user.setSkin(skin); 
<span >   </span>universityService.update(user); 
<span >  </span>} 

做拼音轉換時需導入pinyin4j.jar包
ChinesePinYinTool拼音轉換對象類
package schoolnet.utils;  

 
import net.sourceforge.pinyin4j.PinyinHelper; 
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; 
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; 
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; 
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; 
 
/** 
 * 
 * 漢語拼音對象 
 * 
 * 
 * 
 */ 
public class ChinesePinYinTool { 
 public static void main(String[] args) { 
  String string[]=stringToPinyin("這個"); 
  for (int i = 0; i < string.length; i++) { 
   System.out.println(string[i]); 
  } 
 } 
 /** 
  * 
  * 將字符串轉換成拼音數 
  * 
  * 
  * @param src 
  * @return 
  */ 
 public static String[] stringToPinyin(String src) { 
  return stringToPinyin(src, false, null); 
 } 
 
 /** 
  * 將字符串轉換成拼音數 
  * 
  * 
  * @param src 
  * @return 
  */ 
 public static String[] stringToPinyin(String src, String separator) { 
  return stringToPinyin(src, true, separator); 
 } 
 
 /** 
  * 將字符串轉換成拼音數 
  * 
  * 
  * @param src 
  * @param isPolyphone 
  *   能否查出多音字的拼音 
 
  * 
  * @param separator 
  *   多音字拼音之間的分隔 
  * 
  * @return 
  */ 
 public static String[] stringToPinyin(String src, boolean isPolyphone, 
   String separator) { 
  // 斷定字符串能否為 
 
  if ("".equals(src) || null == src) { 
   return null; 
  } 
  char[] srcChar = src.toCharArray(); 
  int srcCount = srcChar.length; 
  String[] srcStr = new String[srcCount]; 
 
  for (int i = 0; i < srcCount; i++) { 
   srcStr[i] = charToPinyin(srcChar[i], isPolyphone, separator); 
  } 
  return srcStr; 
 } 
 
 /** 
  * 將單個字符轉換成拼音 
  * 
  * @param src 
  * @return 
  */ 
 public static String charToPinyin(char src, boolean isPolyphone, 
   String separator) { 
  // 創立漢語拼音處置 
  HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); 
  // 輸入設置,年夜小寫,音標方 
  defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); 
  defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); 
  StringBuffer tempPinying = new StringBuffer(); 
  // 假如是中 
  if (src > 128) { 
   try { 
    // 轉換得出成果 
    String[] strs = PinyinHelper.toHanyuPinyinStringArray(src, 
      defaultFormat); 
    // 能否查出多音字,默許是查出多音字的第字符 
 
    if (isPolyphone && null != separator) { 
     for (int i = 0; i < strs.length; i++) { 
      tempPinying.append(strs[i]); 
      if (strs.length != (i + 1)) { 
       // 多音字之間用特別符號距離起來 
       tempPinying.append(separator); 
      } 
     } 
    } else { 
     tempPinying.append(strs[0]); 
    } 
 
   } catch (BadHanyuPinyinOutputFormatCombination e) { 
    e.printStackTrace(); 
   } 
  } else { 
   tempPinying.append(src); 
  } 
 
  return tempPinying.toString(); 
 
 } 
 
 public static String hanziToPinyin(String hanzi) { 
  return hanziToPinyin(hanzi, ""); 
 } 
 
 /** 
  * 將漢字轉換成拼音 
  * 
  * @param hanzi 
  * @param separator 
  * @return 
  */ 
 @SuppressWarnings("deprecation") 
 public static String hanziToPinyin(String hanzi, String separator) { 
  // 創立漢語拼音處置 
  HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); 
  // 輸入設置,年夜小寫,音標方 
  defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); 
  defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); 
  String pinyingStr = ""; 
  try { 
   pinyingStr = PinyinHelper.toHanyuPinyinString(hanzi, defaultFormat, 
     separator); 
  } catch (BadHanyuPinyinOutputFormatCombination e) { 
   e.printStackTrace(); 
  } 
  return pinyingStr; 
 } 
 
 /** 
  * 將字符串數組轉換成字符串 
  * 
  * @param str 
  * @param separator 
  *   各個字符串之間的分隔 
  * 
  * @return 
  */ 
 public static String stringArrayToString(String[] str, String separator) { 
  StringBuffer sb = new StringBuffer(); 
  for (int i = 0; i < str.length; i++) { 
   sb.append(str[i]); 
   if (str.length != (i + 1)) { 
    sb.append(separator); 
   } 
  } 
  return sb.toString(); 
 } 
 
 /** 
  * 的將各個字符數組之間銜接起來 
 
  * 
  * 
  * @param str 
  * @return 
  */ 
 public static String stringArrayToString(String[] str) { 
  return stringArrayToString(str, ""); 
 } 
 
 /** 
  * 將字符數組轉換成字符 
  * 
  * 
  * @param str 
  * @param separator 
  *   各個字符串之間的分隔 
  * 
  * @return 
  */ 
 public static String charArrayToString(char[] ch, String separator) { 
  StringBuffer sb = new StringBuffer(); 
  for (int i = 0; i < ch.length; i++) { 
   sb.append(ch[i]); 
   if (ch.length != (i + 1)) { 
    sb.append(separator); 
   } 
  } 
  return sb.toString(); 
 } 
 
 /** 
  * 將字符數組轉換成字符 
  * 
  * 
  * @param str 
  * @return 
  */ 
 public static String charArrayToString(char[] ch) { 
  return charArrayToString(ch, " "); 
 } 
 
 /** 
  * 取漢字的首字 
  * 
  * 
  * @param src 
  * @param isCapital 
  *   能否是年夜 
  * 
  * @return 
  */ 
 public static char[] getHeadByChar(char src, boolean isCapital) { 
  // 假如不是漢字直接前往 
  if (src <= 128) { 
   return new char[] { src }; 
  } 
  // 獲得的拼 
  String[] pinyingStr = PinyinHelper.toHanyuPinyinStringArray(src); 
  // 創立前往對象 
  int polyphoneSize = pinyingStr.length; 
  char[] headChars = new char[polyphoneSize]; 
  int i = 0; 
  // 截取首字 
 
  for (String s : pinyingStr) { 
   char headChar = s.charAt(0); 
   // 首字母能否年夜寫,默許是小 
 
   if (isCapital) { 
    headChars[i] = Character.toUpperCase(headChar); 
   } else { 
    headChars[i] = headChar; 
   } 
   i++; 
  } 
 
  return headChars; 
 } 
 
 /** 
  * 取漢字的首字默許是年夜 
  * 
  * @param src 
  * @return 
  */ 
 public static char[] getHeadByChar(char src) { 
  return getHeadByChar(src, true); 
 } 
 
 /** 
  * 查找字符串首字母 
  * 
  * @param src 
  * @return 
  */ 
 public static String[] getHeadByString(String src) { 
  return getHeadByString(src, true); 
 } 
 
 /** 
  * 查找字符串首字母 
  * 
  * @param src 
  * @param isCapital 
  *   能否年夜寫 
  * @return 
  */ 
 public static String[] getHeadByString(String src, boolean isCapital) { 
  return getHeadByString(src, isCapital, null); 
 } 
 
 /** 
  * 查找字符串首字母 
  * 
  * @param src 
  * @param isCapital 
  *   能否年夜寫 
  * @param separator 
  *   分隔 
  * 
  * @return 
  */ 
 public static String[] getHeadByString(String src, boolean isCapital, 
   String separator) { 
  char[] chars = src.toCharArray(); 
  String[] headString = new String[chars.length]; 
  int i = 0; 
  for (char ch : chars) { 
 
   char[] chs = getHeadByChar(ch, isCapital); 
   StringBuffer sb = new StringBuffer(); 
   if (null != separator) { 
    int j = 1; 
 
    for (char ch1 : chs) { 
     sb.append(ch1); 
     if (j != chs.length) { 
      sb.append(separator); 
     } 
     j++; 
    } 
   } else { 
    sb.append(chs[0]); 
   } 
   headString[i] = sb.toString(); 
   i++; 
  } 
  return headString; 
 } 
} 

數據庫樹立相干函數
fristPinyin : 此函數是將一個中文字符串的第一個漢字轉成拼音首字母 (例如:"好的"->h)
pinyin :此函數是將一個中文字符串對應拼音首字母的每一個相連 (例如:"好的"->hd)
to_pinyin :此函數是將一個中文字符串對應拼音全字母的每一個相連 (例如:"好的"->haode)

CREATE FUNCTION `fristPinyin`(P_NAME VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 
BEGIN 
 DECLARE V_RETURN VARCHAR(255); 
 SET V_RETURN = ELT(INTERVAL(CONV(HEX(left(CONVERT(P_NAME USING gbk),1)),16,10), 
  0xB0A1,0xB0C5,0xB2C1,0xB4EE,0xB6EA,0xB7A2,0xB8C1,0xB9FE,0xBBF7, 
  0xBFA6,0xC0AC,0xC2E8,0xC4C3,0xC5B6,0xC5BE,0xC6DA,0xC8BB, 
  0xC8F6,0xCBFA,0xCDDA,0xCEF4,0xD1B9,0xD4D1),  
 'A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','W','X','Y','Z'); 
 RETURN V_RETURN; 
END 
CREATE FUNCTION `pinyin`(P_NAME VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 
BEGIN 
 DECLARE V_COMPARE VARCHAR(255); 
 DECLARE V_RETURN VARCHAR(255); 
 DECLARE I INT; 
 
 SET I = 1; 
 SET V_RETURN = ''; 
 while I < LENGTH(P_NAME) do 
  SET V_COMPARE = SUBSTR(P_NAME, I, 1); 
  IF (V_COMPARE != '') THEN 
   #SET V_RETURN = CONCAT(V_RETURN, ',', V_COMPARE); 
   SET V_RETURN = CONCAT(V_RETURN, fristPinyin(V_COMPARE)); 
   #SET V_RETURN = fristPinyin(V_COMPARE); 
  END IF; 
  SET I = I + 1; 
 end while; 
 
 IF (ISNULL(V_RETURN) or V_RETURN = '') THEN 
  SET V_RETURN = P_NAME; 
 END IF; 
 
 RETURN V_RETURN; 
END 
CREATE FUNCTION to_pinyin(NAME VARCHAR(255) CHARSET gbk) 
RETURNS VARCHAR(255) CHARSET gbk 
BEGIN 
 DECLARE mycode INT; 
 DECLARE tmp_lcode VARCHAR(2) CHARSET gbk; 
 DECLARE lcode INT; 
 DECLARE tmp_rcode VARCHAR(2) CHARSET gbk; 
 DECLARE rcode INT; 
 DECLARE mypy VARCHAR(255) CHARSET gbk DEFAULT ''; 
 DECLARE lp INT; 
 SET mycode = 0; 
 SET lp = 1; 
 SET NAME = HEX(NAME); 
 WHILE lp < LENGTH(NAME) DO 
  SET tmp_lcode = SUBSTRING(NAME, lp, 2); 
  SET lcode = CAST(ASCII(UNHEX(tmp_lcode)) AS UNSIGNED);  
  SET tmp_rcode = SUBSTRING(NAME, lp + 2, 2); 
  SET rcode = CAST(ASCII(UNHEX(tmp_rcode)) AS UNSIGNED);  
  IF lcode > 128 THEN 
   SET mycode =65536 - lcode * 256 - rcode ; 
   SELECT CONCAT(mypy,pin_yin_) INTO mypy FROM t_base_pinyin WHERE CODE_ >= ABS(mycode) ORDER BY CODE_ ASC LIMIT 1; 
   SET lp = lp + 4; 
  ELSE 
   SET mypy = CONCAT(mypy,CHAR(CAST(ASCII(UNHEX(SUBSTRING(NAME, lp, 2))) AS UNSIGNED))); 
   SET lp = lp + 2; 
  END IF; 
 END WHILE; 
 RETURN LOWER(mypy); 
END;

以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved