⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordqueryreacher.java

📁 使用OSGi框架开发的分布式电子辞典
💻 JAVA
字号:
/* * @(#)WordQueryReacher.java *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Library General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package cn.edu.ynu.sei.dict.web.data;import cn.edu.ynu.sei.dict.core.exception.NotFoundWordException;import cn.edu.ynu.sei.dict.core.service.IDictQueryService;import java.io.IOException;import java.io.PrintWriter;import java.util.logging.Level;import java.util.logging.Logger;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.osgi.framework.ServiceReference;/** * Get the result of the request and pass it to AJAX code. * @author zy * @author 88250 * @version 1.0.0.0, Mar 8, 2008 */public class WordQueryReacher extends HttpServlet {    ServiceReference serviceReference;    IDictQueryService wordReader;    /**     * Constructor with argument.     * @param sr service reference     */    public WordQueryReacher(ServiceReference sr, IDictQueryService wordReader) {        this.wordReader = wordReader;        this.serviceReference = sr;    }    /**      * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.     * @param request servlet request     * @param response servlet response     */    protected void processRequest(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        String input = request.getParameter("word");        String choose = request.getParameter("choose");        System.out.println("choose:"+choose);        response.setContentType("text/html;charset=UTF-8");        PrintWriter out = response.getWriter();        try {            System.out.println("before lookup");            String wordTemp = wordReader.lookupSimilarList(input,choose);            System.out.println("after lookup");            String[] wordList = wordTemp.split("###");            String outputStr = "";            String stringTemp;            for (int i = 0; i < wordList.length - 1; i++) {                stringTemp = wordList[i];                if(wordList[i].contains("'")){                    wordList[i] = wordList[i].replace("'", "\\'");                }                outputStr += "<a href='#' onclick=\"getWord(" + "'" + wordList[i] + "'" + ",'dt','checklist')\">" + stringTemp + "</a>" + "<br>";            }            out.write(outputStr);        } catch (NotFoundWordException ex) {            Logger.getLogger(WordQueryReacher.class.getName()).log(Level.SEVERE, null, ex);            out.write(ex.getMessage());        }         return;    }    // <editor-fold defaultstate="collapsed" desc="HttpServlet 鏂规硶銆傚崟鍑诲乏渚х殑 + 鍙蜂互缂栫級浠g爜銆�>    /**      * Handles the HTTP <code>GET</code> method.     * @param request servlet request     * @param response servlet response     */    protected void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        processRequest(request, response);    }    /**      * Handles the HTTP <code>POST</code> method.     * @param request servlet request     * @param response servlet response     */    protected void doPost(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        processRequest(request, response);    }    /**      * Returns a short description of the servlet.     */    public String getServletInfo() {        return "Short description";    }    // </editor-fold>}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -