List of usage examples for javax.servlet.http HttpServletRequest setCharacterEncoding
public void setCharacterEncoding(String env) throws UnsupportedEncodingException;
From source file:com.persistent.cloudninja.controller.ValidationController.java
/** * The method to validate the tenant id while registering a new tenant * @param request The Http request/*from w w w .j a v a2s . c om*/ * @param response the Http response * @throws IOException */ @RequestMapping("isTenantIdAvailable.htm") public void isTenantIdAvailable(HttpServletRequest request, HttpServletResponse response) throws IOException { TenantEntity tenantEntity; String tenantId = request.getParameter("tenantId"); if (tenantId != null && tenantId.trim().length() > 0) { request.setCharacterEncoding("UTF-8"); tenantEntity = tenantDao.find(tenantId); response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); if (tenantEntity != null) { response.getWriter().write("<valid>true</valid>"); } else { response.getWriter().write("<valid>false</valid>"); } } }
From source file:com.google.code.pathlet.web.PathletAjaxProcessor.java
private void setCharset(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { request.setCharacterEncoding(requestCharset); if (responseSetCharacterEncodingAvailable) { response.setCharacterEncoding(responseCharset); }/*from ww w. j a v a2 s . co m*/ }
From source file:com.sbu.controller.Update_Form_Startup_Controller.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); request.setCharacterEncoding("UTF-8"); Startup startup;/*from w w w . j av a 2 s .c o m*/ List<Member1> members; String username = request.getParameter("email"); String pass = request.getParameter("password"); int id = startupService.Redundant(username); if (id > 0) { startup = startupService.getStartup(id); startup.setName(request.getParameter("supervisorn")); startup.setLastname(request.getParameter("supervisorl")); startup.setEmail(username); startup.setPassword(pass); startup.setStartupName(request.getParameter("name")); startup.setAddress(request.getParameter("address")); startup.setPhone(request.getParameter("tell")); startup.setDescription(request.getParameter("description")); startup.setInstagram(request.getParameter("instagram")); startup.setFacebook(request.getParameter("facebook")); startup.setLinkedin(request.getParameter("linkedin")); startupService.editStartup(startup); /******************* Members **********************/ if (!((memberService.getMemberByStartupId(startup.getIdStartup())) == null)) { members = memberService.getMemberByStartupId(startup.getIdStartup()); for (int j = 1; j < members.size(); j++) { members.get(j).setName(request.getParameter("name" + j)); members.get(j).setLname(request.getParameter("lastname" + j)); members.get(j).setMajor(request.getParameter("major" + j)); members.get(j).setUniversity(request.getParameter("university" + j)); members.get(j).setStartupidStartup(startup); memberService.editMember(members.get(j)); } /** Recommendation **/ Vector<Jobpositions> recomm = startupService.Recommendation(); List<Feed> feedcontent = new ArrayList(); feedcontent = feedService.getAllFeed(); session.setAttribute("recomm", recomm); session.setAttribute("User", startup); session.setAttribute("members", members); session.setAttribute("feedcontent", feedcontent); getServletContext().getRequestDispatcher("/Feed_Startup.jsp").forward(request, response); } } }
From source file:controller.updateProduct.java
private void updateProduct(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); String productID = request.getParameter("productID"); String productName = request.getParameter("productName"); String produceID = request.getParameter("produceID"); String price = request.getParameter("price"); int pri = Integer.parseInt(price); String description = request.getParameter("description"); String quantity = request.getParameter("quantity"); int quant = Integer.parseInt(quantity); String type = request.getParameter("productType"); String resolution = request.getParameter("resolution"); String hdmi = request.getParameter("hdmi"); String usb = request.getParameter("usb"); String model = request.getParameter("Model"); String size = request.getParameter("size"); String warranty = request.getParameter("warranty"); ProductInfo prinfo = new ProductInfo(productID, type, resolution, hdmi, usb, model, size, warranty); Products product = new Products(productID, productName, pri, description, quant, prinfo, produceID); if (ProductsDAO.updateProduct(product)) { out.print(//from w w w. j av a 2s . co m "<center><b><font color='red'>sa thnh cng! </font> <a href = './WEB/admin/showProduct.jsp'>quay v?</a></b></center>"); } else { out.print( "<center><b><font color='red'>tht bi! </font> <a href = './WEB/admin/showProduct.jsp'>quay v?</a></b></center>"); } }
From source file:edu.umich.ctools.sectionsUtilityTool.FriendServlet.java
private void friendRestApiCall(HttpServletRequest request, HttpServletResponse response) throws IOException { request.setCharacterEncoding("UTF-8"); M_log.debug("friendRestApiCall(): called"); Friend myFriend = new Friend(); PrintWriter out = response.getWriter(); response.setContentType("application/json"); Properties appExtSecureProperties = Friend.appExtSecureProperties; if (appExtSecureProperties == null) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out = response.getWriter();/*from www . j ava 2 s .c om*/ out.print(appExtProperties.getProperty("property.file.load.error")); out.flush(); M_log.error("Failed to load system properties(sectionsToolProps.properties) for SectionsTool"); return; } friendApiConnectionLogic(request, response, myFriend); }
From source file:cc.aileron.wsgi.request.WsgiRequestParameterFactoryImpl.java
@Override public WorkflowRequestParameter create(final HttpServletRequest request) throws FileUploadException { try {/*w ww.ja v a 2 s. c o m*/ request.setCharacterEncoding(characterEncodingName); } catch (final UnsupportedEncodingException e) { } if (ServletFileUpload.isMultipartContent(request)) { final DiskFileItemFactory factory = new DiskFileItemFactory(); final ServletFileUpload upload = new ServletFileUpload(factory); factory.setSizeThreshold(1024); upload.setSizeMax(-1); upload.setHeaderEncoding(characterEncodingName); return new RequestMultipart(characterEncoding, upload, request); } return new RequestUrlencoded(request); }
From source file:eu.earthobservatory.org.StrabonEndpoint.DescribeBean.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); if (Common.VIEW_TYPE.equals(request.getParameter(Common.VIEW))) { // HTML visual interface processVIEWRequest(request, response); } else {// invoked as a service processRequest(request, response); }/*from w w w .ja v a 2s .c o m*/ }
From source file:com.francelabs.datafari.servlets.GetFieldsInfo.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response)//from w ww . j a va 2 s.c o m */ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf8"); response.setContentType("application/json"); final PrintWriter out = response.getWriter(); try { // Define the Solr hostname, port and protocol final String solrserver = "localhost"; final String solrport = "8983"; final String protocol = "http"; // Use Solr Schema REST API to get the list of fields final HttpClient httpClient = HttpClientBuilder.create().build(); final HttpHost httpHost = new HttpHost(solrserver, Integer.parseInt(solrport), protocol); final HttpGet httpGet = new HttpGet("/solr/FileShare/schema/fields"); final HttpResponse httpResponse = httpClient.execute(httpHost, httpGet); // Construct the jsonResponse final JSONObject jsonResponse = new JSONObject(); if (httpResponse.getStatusLine().getStatusCode() == 200) { // Status of the API response is OK final JSONObject json = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); final JSONArray fieldsJson = json.getJSONArray("fields"); // Load the list of denied fields final String strDeniedFieldsList = AdvancedSearchConfiguration.getInstance() .getProperty(AdvancedSearchConfiguration.DENIED_FIELD_LIST); final Set<String> deniedFieldsSet = new HashSet<>(Arrays.asList(strDeniedFieldsList.split(","))); for (int i = 0; i < fieldsJson.length(); i++) { final JSONObject field = (JSONObject) fieldsJson.get(i); // If a fieldname has been provided, it means that this // servlet // only // needs to return infos on this specific field if (request.getParameter("fieldName") != null) { final String fieldName = request.getParameter("fieldName"); if (field.getString("name").equals(fieldName)) { jsonResponse.append("field", field); break; } } else { if (!deniedFieldsSet.contains(field.getString("name")) && (!field.has("indexed") || field.getBoolean("indexed")) && !field.getString("name").startsWith("allow_") && !field.getString("name").startsWith("deny_") && !field.getString("name").startsWith("_")) { jsonResponse.append("field", field); } } } out.print(jsonResponse); } else { // Status of the API response is an error logger.error("Error while retrieving the fields from the Schema API of Solr: " + httpResponse.getStatusLine().toString()); out.append( "Error while retrieving the fields from the Schema API of Solr, please retry, if the problem persists contact your system administrator. Error Code : 69026"); } out.close(); } catch (final IOException e) { logger.error("Error while retrieving the fields from the Schema API of Solr", e); out.append( "Error while retrieving the fields from the Schema API of Solr, please retry, if the problem persists contact your system administrator. Error Code : 69026"); out.close(); } }
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 {//from w ww. j a v a 2 s . 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:org.jcommon.com.facebook.servlet.Uploader.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String errormsg = null;/* w ww.j av a 2s. com*/ List<FileItem> list = new ArrayList<FileItem>(); if (ServletFileUpload.isMultipartContent(request)) { FileItem item = null; try { ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); @SuppressWarnings("unchecked") List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> it = items.iterator(); while (it.hasNext()) { item = it.next(); if (!item.isFormField()) { list.add(item); } } } catch (Throwable e) { logger.error("", e); errormsg = "transfer exception"; } } else { errormsg = "not found multipart content"; return; } if (errormsg != null) { error(response, errormsg); return; } for (FileItem item : list) { try { String file_name = item.getName(); String file_id = org.jcommon.com.util.BufferUtils.generateRandom(20); String file_type = file_name.indexOf(".") != -1 ? file_name.substring(file_name.lastIndexOf(".")) : ""; FileOutputStream out_file = null; java.io.File file = new java.io.File(upload_path); if (!file.exists()) if (!file.mkdirs()) { throw new Exception("file mkdir fail! -->" + file.getName()); } String save_name = file_id + file_type; file = new java.io.File(upload_path, save_name); if (!file.exists()) if (!file.createNewFile()) { throw new Exception("file createNewFile fail! -->" + file.getName()); } out_file = new FileOutputStream(file); InputStream is = item.getInputStream(); logger.info("uploading..........."); byte[] b = new byte[1024]; int nRead; while ((nRead = is.read(b, 0, 1024)) > 0) { out_file.write(b, 0, nRead); } try { out_file.close(); out_file.flush(); } catch (IOException e1) { // TODO Auto-generated catch block file.delete(); throw e1; } try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block throw e; } logger.info("done..............."); String msg = "{\"id\":\"" + file_id + "\"}"; logger.info(msg); response.getWriter().println(msg); } catch (Throwable e) { logger.error("", e); errormsg = "transfer exception"; } } if (errormsg != null) { error(response, errormsg); return; } }