List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding
public void setCharacterEncoding(String charset);
From source file:dbservlet.Servlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); try {/* w w w . j av a 2s .c om*/ update(request, response); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.google.publicalerts.cap.validator.CapValidatorServlet.java
private void render(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setAttribute("analyticsId", System.getProperty(ValidatorUtil.GOOGLE_ANALYTICS_ID)); resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/html"); ValidatorUtil.addNoCachableHeaders(resp); resp.setStatus(HttpServletResponse.SC_OK); req.getRequestDispatcher("/validator.jsp").include(req, resp); }
From source file:gwtupload.server.UploadServlet.java
/** * Writes a response to the client./*from w w w . j av a 2 s . c om*/ */ protected static void renderMessage(HttpServletResponse response, String message, String contentType) throws IOException { response.addHeader("Cache-Control", "no-cache"); response.setContentType(contentType + "; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(message); out.flush(); out.close(); }
From source file:fi.jyu.student.jatahama.onlineinquirytool.server.LoadSaveServlet.java
@Override public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { try {//from w ww.j a v a 2s.com // Always server same page. Used to check if Servlet exists. response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); response.setHeader("Cache-Control", "no-cache"); response.setHeader(Utils.httpHeaderNameHello, "Hello!"); // response.setStatus(307); // response.setHeader("Location", "../"); ServletOutputStream out = response.getOutputStream(); out.print("<html><head><META HTTP-EQUIV=REFRESH CONTENT=\"0; URL=../\"><!-- " + Utils.httpHeaderNameHello + ": Hello! --></head><body><a href=\"../\">App</a></body></html>"); out.flush(); } catch (Exception ex) { throw new ServletException(ex); } }
From source file:hd.controller.AddImageToIdeaBookServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w . j a v a2 s. com * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { //to do } else { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = null; try { items = upload.parseRequest(request); } catch (FileUploadException e) { e.printStackTrace(); } Iterator iter = items.iterator(); Hashtable params = new Hashtable(); String fileName = null; while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { params.put(item.getFieldName(), item.getString("UTF-8")); } else if (!item.isFormField()) { try { long time = System.currentTimeMillis(); String itemName = item.getName(); fileName = time + itemName.substring(itemName.lastIndexOf("\\") + 1); String RealPath = getServletContext().getRealPath("/") + "images\\" + fileName; File savedFile = new File(RealPath); item.write(savedFile); String localPath = "D:\\Project\\TestHouseDecor-Merge\\web\\images\\" + fileName; // savedFile = new File(localPath); // item.write(savedFile); } catch (Exception e) { e.printStackTrace(); } } } String ideaBookIdTemp = (String) params.get("txtIdeabookId"); int ideaBookId = Integer.parseInt(ideaBookIdTemp); IdeaBookDAO ideabookDao = new IdeaBookDAO(); String tilte = (String) params.get("newGalleryName"); String description = (String) params.get("GalleryDescription"); String url = "images/" + fileName; IdeaBookPhotoDAO photoDAO = new IdeaBookPhotoDAO(); IdeaBookPhoto ideaBookPhoto = photoDAO.insertIdeaBookPhoto(tilte, description, url, ideaBookId); HDSystem system = new HDSystem(); system.setNotificationIdeaBook(request); response.sendRedirect("MyIdeaBookDetailServlet?txtIdeabookId=" + ideaBookId); } } catch (Exception e) { e.printStackTrace(); } finally { out.close(); } }
From source file:kr.ac.cau.mecs.cass.servletcontextlistener.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { onServletInit(request, response);/*from w ww .ja va 2s .c om*/ response.setContentType("application/json; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); JSONObject jobj = new JSONObject(); Transaction tx = null; Session hsession = HibernateSessionFactory.getSessionFactory().getCurrentSession(); try { tx = hsession.beginTransaction(); jobj = processGet(hsession, request, response); tx.commit(); } catch (Exception e) { jobj.putOpt("error", 1); jobj.putOpt("reason", "server transaction error"); jobj.putOpt("msg", e.getMessage()); e.printStackTrace(); if (tx != null && tx.isActive()) { try { tx.rollback(); } catch (HibernateException e1) { e1.printStackTrace(); } } } jobj.write(out); out.close(); }
From source file:kr.ac.cau.mecs.cass.servletcontextlistener.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { onServletInit(request, response);//from w w w.j ava 2 s . c om response.setContentType("application/json; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); JSONObject jobj = new JSONObject(); Transaction tx = null; Session hsession = HibernateSessionFactory.getSessionFactory().getCurrentSession(); try { tx = hsession.beginTransaction(); jobj = processPost(hsession, request, response); tx.commit(); } catch (Exception e) { jobj.putOpt("error", 1); jobj.putOpt("reason", "server transaction error"); jobj.putOpt("msg", e.getMessage()); e.printStackTrace(); if (tx != null && tx.isActive()) { try { tx.rollback(); } catch (HibernateException e1) { e1.printStackTrace(); } } } jobj.write(out); out.close(); }
From source file:net.cit.tetrad.resource.CommandResource.java
@RequestMapping("/runServerStatus.do") public void runServerStatus(HttpServletResponse response, CommonDto dto) throws Exception { String serverStatusFromMongo = comandService.allServerStatus(dto.getDeviceCode()); response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.setHeader("Cache-Control", "no-cache"); Writer writer = response.getWriter(); writer.write(serverStatusFromMongo); writer.flush();/*from ww w. j a va 2 s. co m*/ }
From source file:org.inbio.ait.web.ajax.controller.QueryController.java
/** * Write the XML to be parsed on the analysis view * Case 0: If there is just one criteria category or especifically these categories * (geographical-taxonomical or or taxonomical-indicator). It means type 0 on xml * @param request// w w w . j a v a 2 s . c om * @param response * @param totalMatch * @param matchesByPolygon * @return * @throws java.lang.Exception */ private ModelAndView writeReponse0(HttpServletRequest request, HttpServletResponse response, Long totalMatch, Long totalPercentage) throws Exception { response.setCharacterEncoding("ISO-8859-1"); response.setContentType("text/xml"); ServletOutputStream out = response.getOutputStream(); StringBuilder result = new StringBuilder(); result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response>"); result.append("<type>0</type>"); result.append("<total>" + totalMatch + "</total>"); result.append("<totalp>" + totalPercentage + "</totalp></response>"); out.println(result.toString()); out.flush(); out.close(); return null; }
From source file:eu.annocultor.tagger.server.controllers.SolrTaggerController.java
@RequestMapping("/doc/**/*.*") public void report(HttpServletRequest request, HttpServletResponse response) throws Exception { String path = merge(request.getServletPath(), request.getPathInfo()); path = path.substring("/doc".length()); response.setCharacterEncoding("UTF-8"); ServletOutputStream outputStream = response.getOutputStream(); try {/* w w w . j ava 2 s . c om*/ IOUtils.copy(new FileInputStream(new File(fetchDoc(), path)), outputStream); } finally { outputStream.close(); } }