Example usage for javax.servlet.http HttpServletResponse setCharacterEncoding

List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setCharacterEncoding.

Prototype

public void setCharacterEncoding(String charset);

Source Link

Document

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.

Usage

From source file:gumga.framework.presentation.push.GumgaNotificationsServlet.java

@RequestMapping("/notifications/dummy")
protected void dummyHtml(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    PrintWriter writer = response.getWriter();
    writer.print("" + "<!DOCTYPE HTML>\n" + "<html>\n" + "    <head>\n"
            + "        <title>Server-Sent Events Servlet example</title>\n"
            + "        <meta charset=\"utf-8\"/>\n" + "        <style>\n" + "            body {\n"
            + "                font-family: sans-serif;\n" + "            }\n" + "        </style>\n"
            + "    </head>\n" + "    <body>\n" + "\n" + "        New messages: <span id=\"foo\"></span>\n"
            + "        <br><br>\n" + "        Messages:<br> \n" + "        <pre id=\"messages\"></pre>\n" + "\n"
            + "\n" + "        <script>\n" + "            \n"
            + "            var params = getSearchParameters();\n" + "\n"
            + "            var eventSource = new EventSource(\"source?gumgaToken=\"+params['gumgaToken']);\n"
            + "            eventSource.onmessage = function (event) {\n"
            + "                //  console.log(event.data);\n"
            + "                var notifications = JSON.parse(event.data);\n"
            + "                document.getElementById('foo').innerHTML = notifications.newMessagesCount;\n"
            + "                \n" + "                var s='';\n" + "                \n"
            + "                for (i=0;i<notifications.newMessages.length;i++){\n"
            + "                    m=notifications.newMessages[i];\n"
            + "                    s+=m.senderLogin+\" \"+m.message+\"\\n\";\n" + "                }\n"
            + "                \n" + "                document.getElementById('messages').innerHTML = s;\n"
            + "                \n" + "            }\n" + "\n" + "            function getSearchParameters() {\n"
            + "                var prmstr = window.location.search.substr(1);\n"
            + "                return prmstr != null && prmstr != \"\" ? transformToAssocArray(prmstr) : {};\n"
            + "            }\n" + "\n" + "            function transformToAssocArray(prmstr) {\n"
            + "                var params = {};\n" + "                var prmarr = prmstr.split(\"&\");\n"
            + "                for (var i = 0; i < prmarr.length; i++) {\n"
            + "                    var tmparr = prmarr[i].split(\"=\");\n"
            + "                    params[tmparr[0]] = tmparr[1];\n" + "                }\n"
            + "                return params;\n" + "            }\n" + "\n" + "            \n" + "\n"
            + "        </script>\n" + "    </body>\n" + "</html> " + "");
    writer.close();//from w  ww .  j a v a  2 s . co  m
}

From source file:net.proest.librepilot.web.handler.ObjectHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setCharacterEncoding("utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    if (request.getMethod().equals("POST")) {
        handlePost(target, baseRequest, request, response);
    } else if (request.getMethod().equals("GET")) {
        handleGet(target, baseRequest, request, response);
    }/*from  w w w  . ja  va  2 s  . c om*/
    baseRequest.setHandled(true);
}

From source file:com.atlassian.plugins.studio.storage.examples.it.IntegrationTestServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    res.setCharacterEncoding("UTF-8");
    res.setContentType("text/html");

    try {//from  w  w  w .j a v  a  2 s.  co  m
        TestSuite suite = new TestSuite(storageService);

        doExec(res.getWriter(), suite, getTests(suite));

    } finally {
        res.getWriter().close();
    }
}

From source file:fr.rktv.iamweb.services.servlets.Register.java

/**
 * @see Register#doPost(HttpServletRequest request, 
 * HttpServletResponse response)//from   www.j  a  v a2s  .  com
 *  @param request -HttpServletRequest
 *  @param response -HttpServletResponse
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    String resString = "Succesfully Created Administrative Account in";
    try {
        StringBuffer buffReq = new StringBuffer();
        String line = null;
        BufferedReader reader = request.getReader();
        while ((line = reader.readLine()) != null)
            buffReq.append(line);

        Credentail user = new ObjectMapper().readValue(buffReq.toString(), Credentail.class);
        if (authenticationDAO.licensedUserAlreadyExist(user.getLicense())) {
            resString = "Licensed Account already Exists.Contact Admin for new License";
        } else {
            if (authenticationDAO.checkValidLicense(user.getLicense())) {
                authenticationDAO.addUser(user);
            } else {
                resString = "Invalid License.Contact Admin for correct License";
                LogManager.log("Invalid License.Contact Admin for correct License", this.getClass(),
                        Level.ERROR);
            }
        }
    } catch (Exception exp) {
        resString = "Error while creating Account. Contact Admin";
        LogManager.log(exp.getMessage(), this.getClass(), Level.ERROR);
    } finally {
        out.write(resString);
        out.flush();
        out.close();
    }

}

From source file:com.ibm.mds.MobileServlet.java

private void doResp(String jsonMsg, HttpServletResponse resp) throws IOException {
    resp.setContentType("application/json");
    resp.setCharacterEncoding("UTF-8");
    resp.getWriter().write(jsonMsg);//  w w  w. ja  va2s  .  co  m
    resp.setStatus(200);
}

From source file:mn.sict.krono.renders.UploadFile.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w  ww .  j a va2 s .co  m
 *
 * @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 {
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");

    String templateName = request.getParameter("demo_name");
    Part filePart = request.getPart("demo_img");
    try {
        // String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString(); // MSIE fix.
        InputStream fileContent = filePart.getInputStream();
        System.out.println(templateName);
        File file = new File("uploads/" + templateName + ".png");
        System.out.println(file.getAbsolutePath());
        OutputStream outputStream = new FileOutputStream(file);
        IOUtils.copy(fileContent, outputStream);
        outputStream.close();

        Thumbnails.of(new File("uploads/" + templateName + ".png")).size(500, 707).outputFormat("PNG")
                .toFiles(Rename.NO_CHANGE);

    } catch (NullPointerException ex) {
        System.out.println("null param");
    }

    response.getWriter().write("uploaded lmao");

    System.out.println("fking shit");
    response.sendRedirect("init.jsp?req=" + templateName);
}

From source file:com.casker.portfolio.controller.RecentlyAdminController.java

/**
 *   ?/*from  ww  w  .jav  a2 s  .c o  m*/
 * 
 * @return
 */
@ResponseBody
@RequestMapping(value = "/manegement/recently/write", method = RequestMethod.POST)
public String writeRecently(HttpServletResponse response, Recently recently) {

    portfolioService.addRecently(recently);

    response.setCharacterEncoding("UTF-8");
    return ScriptUtil.alertAndRedirect("? ??.", "/admin/manegement/recently");
}

From source file:com.casker.portfolio.controller.RecentlyAdminController.java

/**
 *   //from  w ww  .  j  av a  2s.c o  m
 * 
 * @return
 */
@ResponseBody
@RequestMapping(value = "/manegement/recently/edit", method = RequestMethod.POST)
public String editRecently(HttpServletResponse response, Recently recently) {

    portfolioService.editRecently(recently);

    response.setCharacterEncoding("UTF-8");
    return ScriptUtil.alertAndRedirect("? ?.", "/admin/manegement/recently");
}

From source file:com.gae.ImageGetAllSvlt.java

@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/plain");
    resp.setCharacterEncoding("utf-8");
    /*//from  www.  ja  v  a2  s.  co m
    String out = "";
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Query query = pm.newQuery(com.gae.Imagedat.class);
     try {
       List<Imagedat> results = (List<Imagedat>)pm.newQuery(query).execute();
       if (results.iterator().hasNext()) {             
     for (Imagedat img : results) {
           out += img.getGuestname()+"<i>";
           out += img.getEmail()+"<i>";
           out += img.getFiletitle()+"<i>";
           out += img.getComment()+"<i>";
           out += img.getFilename()+"<i>";
           //out += img.getContent().getBytes()+"<i>";                  
           out += img.getDate()+"<r>";   
        }
        resp.getWriter().println(out);             
       } else {
       resp.getWriter().println("NO:???"); 
       }
    } finally {
       pm.close();
    }
    */

    //String out = "[";
    String out = "";
    Query query = new Query("imagestore"); //1
    List<Entity> entity = ds.prepare(query).asList(FetchOptions.Builder.withOffset(0));
    for (Entity e : entity) {
        String skey = e.getKey().toString();
        out += skey + "<p>";
        String guestname = (String) e.getProperty("guestname");
        out += guestname + "<p>";
        String email = (String) e.getProperty("email");
        out += email + "<p>";
        String comment = (String) e.getProperty("comment");
        out += comment + "<p>";
        String image = (String) e.getProperty("image");
        out += image + "<e>";
        //moddate
        //String moddate = (String) e.getProperty("moddate");
        //out += moddate + "<e>";
        //String os = (String) o.getProperty("os");
        //String memory = (String) o.getProperty("memory");
        //String price = o.getProperty("price").toString();
        //String orddate = o.getProperty("orddate").toString();
        //out += "{\"skey\": \"" + skey + "\", \"guestname\": \"" + guestname + "\", \"email\": \"" + email + "\", \"comment\": \"" + comment + "\"},";

    }
    //out += "]";
    resp.getWriter().println(out.substring(0, out.length() - 3));

    /*
    JSONObject jsonobj=new JSONObject();
    Query query = new Query("imagestore"); //1
     List<Entity> entity = ds.prepare(query).asList(FetchOptions.Builder.withOffset(0));
     int i = 0;
     for (Entity e : entity) {
    String skey = e.getKey().toString();
    jsonobj.put("skey", skey);
     String guestname = (String) e.getProperty("guestname");
     jsonobj.put("guestname", guestname);
     String email = (String) e.getProperty("email");
     jsonobj.put("email", email);
     String comment = (String) e.getProperty("comment");
     jsonobj.put("comment", comment);           
     }
     resp.getWriter().println(jsonobj);
     */
}

From source file:ju.ehealthservice.images.SaveImage.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  w  w.  ja v  a  2  s .  c om*/
 *
 * @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 {
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    String ajaxUpdateResult = "";
    try {
        /* TODO output your page here. You may use following sample code. */
        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
        List<FileItem> items = upload.parseRequest(request);
        String fileName = "";
        for (FileItem item : items) {
            if (item.isFormField()) {
                fileName = item.getString();
            } else {
                String filePath = Constants.IMAGE_REPOSITORY_PATH + fileName + ".jpg";
                File storeFile = new File(filePath);
                metadata.getData(fileName);
                metadata.updateImage(true);
                item.write(storeFile);
            }
        }
        ajaxUpdateResult = "true";
    } catch (FileUploadException ex) {
        ex.printStackTrace();
        ajaxUpdateResult = "false";
    } catch (Exception ex) {
        ex.printStackTrace();
        ajaxUpdateResult = "false";
    }
    out.print(ajaxUpdateResult);
}