📄 addword.java
字号:
/* * @(#)AddWord.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.DuplicateWordException;import cn.edu.ynu.sei.dict.core.exception.NotFoundWordException;import cn.edu.ynu.sei.dict.core.service.IDictEditService;import cn.edu.ynu.sei.dict.core.service.IDictQueryService;import cn.edu.ynu.sei.dict.core.service.User;import cn.edu.ynu.sei.dict.core.service.Word;import cn.edu.ynu.sei.dict.plugin.user.service.IUserManager;import java.io.*;import java.util.logging.Level;import java.util.logging.Logger;import javax.servlet.*;import javax.servlet.http.*;/** * Handle add new word. * @author zy * @version 1.0.0.0, Mar 13, 2008 */public class AddWord extends HttpServlet { private IDictQueryService wordReader; private IDictEditService wordWriter; private IUserManager userManager; /** * default constructor. */ public AddWord() { } /** * constructor with argument. * @param qs * the interface for reading word. * @param ds * the interface for writering word. * @param um * the interface for user management. */ public AddWord(IDictQueryService qs, IDictEditService ds, IUserManager um) { this.wordReader = qs; this.wordWriter = ds; this.userManager = um; } /** * 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 { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); if (session.getAttribute("user") == null) { out.write("您还没有登录,请先登录!"); } else { User user = (User)session.getAttribute("user"); String self = request.getParameter("word"); String def = request.getParameter("def"); def = new String(def.getBytes("iso-8859-1"),"utf-8"); Word vocabulary = new Word(); vocabulary.defComeFrom = user.name; vocabulary.self = self; vocabulary.definition = def; try { wordWriter.addVocabulary(vocabulary); out.write("添加成功!"); } catch (DuplicateWordException ex) { out.write(ex.getMessage()); } } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * 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 + -