Les résultats de la recherche de la page d'accueil 360 sont les suivants
1. La structure du répertoire principal du réseau du campus Schoolnet terminé est la suivante
Réalise principalement la recherche intelligente et le remplacement de la peau qui soutient les premières lettres chinoises, et les lettres complètes de Pinyin
L'effet de page est le suivant
Le code principal principal est le suivant
1.head.jsp
<% @ page import = "java.io.file"%> <% @ page linguisse = "java" import = "java.util. *" pageencoding = "utf-8"%> <% @ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%> <% @ taglib prefix = "fn" fn " uri = "http://java.sun.com/jsp/jstl/fonctions"%> <! doctype html public "- // w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1 <Html> <A-Head> <Title> Campus Network Home Page </ Title> <Link Rel = "Stylesheet" Href = "/ SchoolNet / CSS / index.css" type = "Text / CSS" /> <Script Type = "Text / Javascript" Src = "/ SchoolNet / JS / JS src = "/ scolairet / js / jquery.js"> </ script> <script src = "/ scolairet / js / jQuery-Ui.js"> </ script> <script type = "text / javascript" src = "/ javascript" src = "/ Schoolnet / myajax / ajax_uni.js"> </ script> <script type = "text / javascript" src = "/ scolairet / js / style.js"> </ script> <c: if test = "$ {loginuser.skin.id! = null}"> <script type = "text / javascript"> $ (document). {var photo = '$ {Loginuser.skin.photo}'; $ ("body"). CSS ("Background", "# f6f6f6 URL (/ Schoolnet / Images / PF /" + Photo + ") Top Repeal"); }); </ script> </c: if> </ head> <body> <div> <div id = "searchType"> <a href = "javaScript: void (0)" onClick = "setSearchType (this), setSearch ()" name = "searchdatas" id = "books.png"> data </a> <a href = "javascript: Void (0)" onclick = "setSearchType (this), setSearch ()" name = "searchsongs" id = "t01d566d0c28b32ddad.png"> music </a> <a href = "javascript: void (0)" onclick = "SetSearchType (this), sesearch ()" name = "searchNews" id = "journal.png"> news </a> <a href = "javascript: void (0)" onclick = "sesearchType (this), setSearch ()" name = "searchxiaoshuos" id = "Library.png"> roman </a> <a href = "javascript: void (0)" onclick = "setSearchType (this), setSearch ()" name = "searcharticles" id = "blog.gif"> log </a> </ div> <form id = "search-form" action = "/ scolairet / autre.do? file src = "/ scolairet / images / front / books.png" id = "searchg" style = "margin-bottom: -10px" /> <input type = "text" name = "search" id = "topsearchText" onKeyUp = "sesearch ()" onfocus = "newsearch ()" "//> <entrée id =" EntwearchType " <ul id = "setSearch"> </ul> </div> <div id = "MainMenu"> <ul> <li> <a href = "/ Schoolnet / Login.do? Flag = GoHomeui" Id = "* Menu_Selected"> <span> Campus Network </a> </a> href = "/ Schoolnet / Login.do? Flag = GoHomeui"> <span> Centre personnel </span> </a> </li> <li> <a href = "/ scolairet / profil.do? Flag = GoHomePageUi"> <span> My Home </ Span> </a> </li> <li> <a href = "javascrip </a> <ul> <li> <a href = "/ scolairet / shou.do? Flag = shuoshuo & pagenow = 1"> parler </a> </li> <li> <a href = "/ scolairet / album.do? Flag = myalbumui & pagenow = 1 & userid = $ {LoginUser.id}"> album </a> href = "/ scolairet / ami.do? Flag = MyFriendUi & pagenow = 1"> amis </a> </li> <li> <a href = "/ scolairet / article.do? Flag = ArticleUi & pagenow = 1 & userid = $ {loginuser.id}"> Log </a> </li> <li> <A href = "/ Schoolnet / Article.do? Flag = ArticleUi & PageNow = 1 & userid = $ {LoginUser.id}"> log </a> </li> <li> <a href = "/ scolairet / musi.do? Flag = gomusichome & pagenow = 1"> musique </a> </li> <li> <A href = "/ scolairet / news.do? flag = grewsui & typeid = 1 & pagenow = 1"> news </a> </li> <li> <a href = "/ scolairet / datas.do? Flag = godatasui & pagenow = 1 & action = all"> data </a> </li> <li> <a href = "/ Schoolnet / xiaoshuo.do? Flag = goxiaoshuoui & pagenow = 1 & id = all"> roman </a> </li> <li> <a href = "/ scolairet / skin.do? .do? flag = goshareui & pagenow = 1 "> Nouvelles choses </a> </li> </ul> </li> <li> <a href =" javascrip <li> <a href = "/ scolairet / autre.do? Flag = goaboutui # 2"> sitemap </a> </li> <li> <a href = "/ scolairet / autre.do? Flag = goaboutui # 2"> sitemap </a> </li> <li> <a href = "/ schoolnet / autre.do? </li> <li> <a href = "/ scolairet / autre.do? Flag = goaboutui # 4"> liens d'amis </a> </li> </ul> </li> </li> <li> <a href = "javascript: void (0)"> <span> </pan> </a> <ul> <li> <A) href = "/ Schoolnet / registre.do? Flag = udui"> Modifier les informations personnelles </a> </li> <li> <a href = "/ scolairet / login.do? Flag = Logout"> exit </a> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> </li> test = "$ {LoginUser! = null}"> <div id = "page-wrap"> <ul> <li id = "menu_selected"> <a id = "menu_selected" href = "/ scolairet / login.do? marge-top: -18px; marge-gauche: -10px "/> </a> <ul> <li> <a href =" / scolairet / registre.do? file </ul> </div> </c: if> </div> </ody> </html> 2. Fonctions JS principales
// Utilisé pour définir le type de recherche de commutation et afficher le contenu populaire (cinq premiers) correspondant (informations, musique, nouvelles, romans, journaux) lors du déclenchement de la mise au point du contrôle d'entrée. fonction setSearchType (o) {$ ("# searchType a"). reposovelass ("current"); $ (o) .AddClass ("Current"); var inputSearchType = $ (o) .text (); $ ("# inputSearchType"). Val ("search" + inputSearchType); document.getElementById ("Search-Form"). Action = "/ Schoolnet / autre.do? Flag =" + O.Name + "& SearchPageNow = 1"; document.getElementById ("Recherche-form"). name = o.name; document.getElementById ("SearchImg"). Src = "/ SchoolNet / Images / Front /" + O.id; $ ("# topsearchText"). show (); $ ("# SearchFriendssSS"). Hide (); if (o.name == "searchfriends") {$ ("# topsearchText"). Hide (); $ ("# searchfriendssS"). show (); }} // Utilisé pour définir le contenu pour afficher les invites intelligentes (les dix premières correspondances dans la recherche floue) setSearch () {var v = document.getElementById ("topsearchText"). Valeur; var type = document.getElementById ("Recherche-form"). Nom; if (v.length == 0) {$ ("# setSearch"). html (""); } if (v.length> 0) {$ .ajax ({cache: true, type: "post", url: "/ scolairet / changeinfo", data: {"action": "setSearch", "search": v, "searchType": type}, async: false, datatype: "html", succès: fonction (données) { $ ("# setSearch"). html (""); $ ("# setSearch"). }; } Fichiers Java principaux
if ("searchsongs" .equals (searchType)) <span style = "white-espace: pre"> </span> {<span style = "white-space: pre"> </span> string namehead [] = chineSepinyIntool.GetheAdByString (search); <span style = "blanc-espace: pre"> </ span> string nameheadString = ""; <span style = "White-Space: pre"> </ span> pour (int i = 0; i <namehead.length; i ++) {<span style = "white-espace: pre"> </span> nameheadString + = namehead [i]; <span style = "blanc-espace: pre"> </span>} <span style = "white-space: pre"> </span> string nameall [] = chineSepinyIntool.stringtopinyin (search); <span style = "blanc-espace: pre"> </ span> chaîne nameallString = ""; <span style = "blanc-espace: pre"> </span> pour (int i = 0; i <nameall.length; i ++) {<span style = "white-espace: pre"> </span> nameallstring + = nameall [i]; <span style = "White-Space: pre"> </span>} <span style = "White-Space: Pre"> </span> Liste <Song> Songs = UniversityService.ExECUTEQUERYBYPAGE ("From Song Where To_pinyin (Name) Like '%" + nameallString + "%' ou pinyin (nom) Like '%" + nameheadString + "%'", null, 1, 10); <span style = "White-Space: pre"> </span> pour (int i = 0; i <songs.size (); i ++) <span style = "white-espace: pre"> </span> {<span style = "white-space: pre"> </span> con + = "<li> <a target = 'blank' ' href = '/ scolarnet / music.do? Flag = gopatentDisplay & pid = "+ songs.get (i) .getPatent (). getID () +"'> "+ songs.get (i) .getName () +" </a> </li> "; <span style = "White-Space: pre"> </span>} <span style = "White-Space: pre"> </span> if (Songs.Size ()! = 0) {<span style = "White-Space: Pre"> </span> Con + = "<li> <a href = 'Javascript: Void (0)' onClick = 'Hideli ()' style = 'affichage: en ligne; float: à droite; marge-droite: 8px;'> close </a> </li> "; <span style = "White-espace: pre"> </span>} <span style = "White-espace: pre"> </span> else {<span style = "white-espace: pre"> </span> con + = "<li> <a href = 'javascript: void (0)' onclick = 'hideli ()' style = 'affiche:' '> un non arbitraire résultat arbitraire </a>; <span style = "blanc-espace: pre"> </span>} <span style = "white-espace: pre"> </span> out.write (con); <span style = "blanc-espace: pre"> </span> out.close (); <span style = "blanc-espace: pre"> </span>} else if ("setpifu" .equals (action)) <span style = "white-space: pre"> </span> {<span style = "white-space: pre"> </span> string skinId = request.getParameter ("skinId"); <span style = "White-espace: pre"> </span> peau peau = (peau) UniversityService.findByid (skin.class, entier.valueof (skierID)); <span style = "white-space: pre"> </span> utilisateurs utilisateur = (utilisateurs) request.getSession (). getAttribute ("Loginuser"); <span style = "blanc-espace: pre"> </span> user.setskin (peau); <span style = "blanc-espace: pre"> </span> UniversityService.update (utilisateur); <span style = "blanc-espace: pre"> </span>} Lorsque vous effectuez une conversion de pinyin, vous devez importer le package pinyin4j.jar
Classe d'outils de conversion CHINEPINYINTOOL PINYIN
Package SchoolNet.utils;
importer net.sourceforge.pinyin4j.pinyinhelper; importer net.sourceforge.pinyin4j.format.hanyupinyincasEType; importer net.sourceforge.pinyin4j.format.hanyupinyinoutputformat; importer net.sourceforge.pinyin4j.format.hanyupinyIntOnType; importer net.sourceforge.pinyin4j.format.exception.badhanyupinyinoutputformatCombination; / ** * * Tool Pinyin chinois * * * * / classe publique ChineSepinyIntool {public static void main (string [] args) {String String [] = stringTopinyIn ("this"); for (int i = 0; i <string.length; i ++) {System.out.println (String [i]); }} / ** * * Convertir une chaîne en un numéro de pinyin * * * @param src * @return * / public static String [] StringTopinyIn (String src) {return stringTopinyin (src, false, null); } / ** * Convertir une chaîne en un numéro de pinyin * * * @param src * @return * / public static string [] stringTopinyin (String src, string séparateur) {return stringTopinyin (src, true, séparateur); } / ** * Convertir une chaîne en un certain nombre de pinyin * * * @param src * @param ispolyphone * Que ce soit le pinyin de caractères polyphoniques * * @param séparateur * séparation entre les caractères polyphoniques * * @return * / public static string [] stringtopinyin (string src, booléen ispolyphone, string séparateur) {// déterminer si la chaîne est iff ("" .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, séparateur); } return srcstr; } / ** * Convertir un seul caractère en pinyin * * @param src * @return * / public static String chartopinyin (char src, booléen ispolyphone, string séparateur) {// Créer un traitement chinois de pinyin hanyupinyinoutputformat defaultformat = new hanyupinyinoutformat (); // Paramètres de sortie, case supérieur, symbole phonétique defaultFormat.SetCasetype (hanyupinyincasetype.lowercase); defaultFormat.SetToneType (hanyupinyIntOnType.without_tone); StringBuffer temppinying = new StringBuffer (); // si c'est moyen if (src> 128) {try {// converti pour obtenir la chaîne de résultats [] strs = pinyInHelper.tohanyupinyInstringArray (src, defaultFormat); // Que ce soit pour trouver des caractères polyphoniques, la valeur par défaut est de trouver le caractère des caractères polyphoniques if (ispolyphone && null! = Séparateur) {for (int i = 0; i <str.length; i ++) {temppinying.append (strs [i]); if (str.length! = (i + 1)) {// Les caractères polyphoniques sont séparés par des symboles spéciaux temppinying.append (séparateur); }}} 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, ""); } / ** * Convertir les caractères chinois en pinyin * * @param hanzi * @param séparateur * @return * / @suppresswarnings ("dépréciation") String statique publique Hanzitopinyin (String Hanzi, séparateur de chaîne) {// Créer des pinyin chinois HanyupinyinoutFormatFormat = new HanyupinyInOuttformtformat (); // Paramètres de sortie, case supérieur, symbole phonétique defaultFormat.SetCasetype (hanyupinyincasetype.lowercase); defaultFormat.SetToneType (hanyupinyIntOnType.without_tone); String pinyingStr = ""; essayez {pinyingStr = pinyInhelper.tohanyupinyinstring (hanzi, defaultformat, séparateur); } catch (badhanyupinyInOutputFormatcombination e) {e.printStackTrace (); } return pinyingStr; } / ** * Convertir un tableau de chaîne en une chaîne * * @param str * @param séparateur * Séparation entre chaque chaîne * * @return * / public static string stringArrayToString (string [] str, string séparateur) {stringBuffer sb = new StringBuffer (); for (int i = 0; i <str.length; i ++) {sb.append (str [i]); if (str.length! = (i + 1)) {sb.append (séparateur); }} return sb.toString (); } / ** * Connectez chaque tableau de caractères * * * @param str * @return * / public static string stringArayToString (string [] str) {return StringArayToString (str, ""); } / ** * Convertir un tableau de caractères en caractères * * * @param str * @param séparateur * Séparation entre les chaînes individuelles * * @return * / public static static chararraytoString (char [] ch, string séparateur) {StringBuffer sb = new StringBuffer (); for (int i = 0; i <ch.length; i ++) {sb.append (ch [i]); if (ch.length! = (i + 1)) {sb.append (séparateur); }} return sb.toString (); } / ** * Convertir un tableau de caractères en caractères * * * @param str * @return * / public static static chararraytoString (char [] ch) {return chararraytoString (ch, ""); } / ** * Obtenez le premier caractère du caractère chinois * * * @param src * @param iscapital * est-il grand * * @return * / public static char [] getheadbychar (char src, boolean iscapital) {// Si pas le caractère chinois, return directement if (src <= 128) {return new Char [] {src}; } // L'orthographe obtenue [] pinyingStr = pinyInhelper.tohanyupinyinstringArray (src); // Créer un objet de retour int polyphonesize = pinyingStr.length; char [] Headchars = nouveau char [polyphonesize]; int i = 0; // Intercepter le premier mot pour (String S: PinyingStr) {char hentchar = s.charat (0); // Si la première lettre est capitalisée, la valeur par défaut est petite if (isCapital) {Headchars [i] = caractères } else {Headchars [i] = baisses; } i ++; } retour des têtes; } / ** * La valeur par défaut pour prendre le premier mot pour les caractères chinois est grande * * @param src * @return * / public static char [] getheadbychar (char src) {return getheadbychar (src, true); }! } / ** * Trouvez la lettre initiale de la chaîne * * @param src * @param iscapital * s'il est capitalisé * @return * / public static static [] getheadBystring (String src, true); } / ** * Trouvez la lettre initiale de la chaîne * * @param src * @param iscapital * est-ce que c'est capitalisé * @return * / public static static [] getheadBystring (String src, booléen iscapital) {return getheadBystring (src, iscapital, null); } / ** * Trouvez les initiales de chaîne * * @param src * @param iscapital * si la capitalisation * @param séparateur * séparée * * @return * / public static static [] getheadBystring (String src.toicharay (); String [] headstring = new String [chars.length]; int i = 0; pour (char ch: char) {char [] chs = getheadbychar (ch, iscapital); StringBuffer sb = new StringBuffer (); if (null! = séparateur) {int j = 1; pour (char ch1: chs) {sb.append (ch1); if (j! = chs.length) {sb.append (séparateur); } j ++; }} else {sb.append (chs [0]); } headstring [i] = sb.toString (); i ++; } return headstring; }} La base de données construit des fonctions connexes
Fristpinyin: Cette fonction convertit le premier caractère chinois d'une chaîne chinoise dans la première lettre du pinyin (par exemple: "ok" -> h)
Pinyin: Cette fonction relie chacune des premières lettres de pinyin d'une chaîne chinoise (par exemple: "OK" -> HD)
to_pinyin: cette fonction relie chacune des lettres complètes d'une chaîne chinoise correspondant au pinyin (par exemple: "ok" -> haode)
Créer une fonction `Fristpinyin` (p_name varchar (255)) renvoie varchar (255) charset utf8 begin declare v_return varchar (255); Set v_return = elt (Interval (conv (hex (gauche (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»); Retour v_return; End Create Fonction `pinyin` (p_name varchar (255)) renvoie varchar (255) charset utf8 begin de déclarer v_compare varchar (255); Declare V_return Varchar (255); DÉCLAGE I INT; Définir i = 1; Set v_return = ''; tandis que je <le long (p_name) définit v_compare = substr (p_name, i, 1); If (v_compare! = '') Alors #set v_return = concat (v_return, ',', v_compare); Set v_return = concat (v_return, fristpinyin (v_compare)); #Set v_return = fristpinyin (v_compare); Terminer si; Définir i = i + 1; terminer pendant que; If (isNull (v_return) ou v_return = '') alors définissez v_return = p_name; Terminer si; Retour v_return; End Create Fonction to_pinyin (Name Varchar (255) Charset GBK) Renvoie VARCHAR (255) Charset GBK Begin de déclarer MyCode int; DÉCLARIEZ TMP_LCODE VARCHAR (2) CHARSET GBK; Declare LCODE INT; DÉCLARIEZ TMP_RCODE VARCHAR (2) CHARSET GBK; DÉCLARE RCODE INT; DÉCLAREZ MYPY VARCHAR (255) CHARSET GBK DEFAULT ''; Déclarer LP INT; Définir mycode = 0; Définir lp = 1; Set name = hex (nom); Tandis que lp <longueur (nom) définit tmp_lcode = substring (nom, lp, 2); Set lCode = Cast (ASCII (UNSEX (tmp_lcode)) en tant que non signé); Définir tmp_rcode = substring (nom, lp + 2, 2); Set rCode = Cast (ASCII (UNSEX (tmp_rcode)) en tant que non signé); Si LCODE> 128, définissez MyCode = 65536 - LCODE * 256 - RCODE; Sélectionnez Concat (mypy, pin_yin_) dans mypy from t_base_pinyin où code_> = abs (mycode) Ordre par code_ limit 1; Définir lp = lp + 4; Else set mypy = concat (mypy, char (cast (ASCII (unxx (substring (nom, lp, 2))) en tant que non signé))); Définir lp = lp + 2; Terminer si; Terminer pendant que; Retourne inférieur (mypy); FIN;
Ce qui précède est tout le contenu de cet article. J'espère que cela sera utile à l'apprentissage de tous et j'espère que tout le monde soutiendra davantage Wulin.com.