List of usage examples for javax.servlet.http HttpServletRequest getParameterMap
public Map<String, String[]> getParameterMap();
From source file:controler.category.AddCategoryServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Category category = new Category(); CategoryDAO categoryDAO = new CategoryDAO(); try {// www.j ava 2s .c om BeanUtils.populate(category, request.getParameterMap()); if (categoryDAO.connect()) { int rows = categoryDAO.addCategory(category); } } catch (IllegalAccessException ex) { Logger.getLogger(AddCategoryServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { Logger.getLogger(AddCategoryServlet.class.getName()).log(Level.SEVERE, null, ex); } finally { categoryDAO.disconnect(); response.sendRedirect(request.getSession().getServletContext().getContextPath() + "/AdminViewCategory"); } }
From source file:com.ccc.webapp.http.mappers.MappingJacksonJsonpView.java
/** * Prepares the view given the specified model, merging it with static * attributes and a RequestContext attribute, if necessary. * Delegates to renderMergedOutputModel for the actual rendering. * @see #renderMergedOutputModel/*w w w. jav a2s . c o m*/ */ @Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { if ("GET".equals(request.getMethod().toUpperCase())) { @SuppressWarnings("unchecked") Map<String, String[]> params = request.getParameterMap(); if (params.containsKey("callback")) { response.getOutputStream().write(new String(params.get("callback")[0] + "(").getBytes()); super.render(model, request, response); response.getOutputStream().write(new String(");").getBytes()); response.setContentType("application/javascript"); } else { super.render(model, request, response); } } else { super.render(model, request, response); } }
From source file:fr.paris.lutece.plugins.extend.web.servlet.ExtendContent.java
/** * {@inheritDoc}/*from ww w. j a v a 2s . com*/ */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ResourceExtenderDTO resourceExtender = new ResourceExtenderDTO(); try { BeanUtils.populate(resourceExtender, request.getParameterMap()); } catch (IllegalAccessException e) { AppLogService.error("Unable to fetch data from request", e); } catch (InvocationTargetException e) { AppLogService.error("Unable to fetch data from request", e); } IResourceExtenderService extenderService = SpringContextService .getBean(ResourceExtenderService.BEAN_SERVICE); String strHtml = extenderService.getContent(resourceExtender.getIdExtendableResource(), resourceExtender.getExtendableResourceType(), resourceExtender.getExtenderType(), resourceExtender.getParameters(), request); PrintWriter out = response.getWriter(); out.println(strHtml); }
From source file:de.iew.web.controllers.IdentityController.java
@RequestMapping(value = "/loginerror.html") public ModelAndView loginError(HttpServletRequest request) { LoginForm loginForm = createLoginForm(); DataBinder binder = new DataBinder(loginForm); MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(request.getParameterMap()); binder.bind(mutablePropertyValues);/*from ww w. j a v a2s. c o m*/ ModelAndView mav = new ModelAndView(this.viewScript); mav.addObject(this.loginFormModelKey, loginForm); mav.addObject("error", true); mav.addObject("loginErrorMessage", "errors.login.denied.message"); // Hole den Login Fehler und verffentliche die Fehlermeldungen Exception e = (Exception) request.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); if (e instanceof ValidatingFormAuthenticationFilter.LoginFormValidationException) { ValidatingFormAuthenticationFilter.LoginFormValidationException ex = (ValidatingFormAuthenticationFilter.LoginFormValidationException) e; BindingResult res = ex.getErrors(); /* Oh man :-D @see http://stackoverflow.com/questions/6704478/access-spring-mvc-bindingresult-from-within-a-view */ mav.addObject(BindingResult.MODEL_KEY_PREFIX + this.loginFormModelKey, res); } return mav; }
From source file:org.schedoscope.metascope.controller.MetascopeMainController.java
private String getParameter(HttpServletRequest request, String parameterKey) { Map<String, ?> inputFlashMap = RequestContextUtils.getInputFlashMap(request); String[] parameterValues = request.getParameterMap().get(parameterKey); if (parameterValues != null && parameterValues.length > 0) { return parameterValues[0]; }// w w w . j a v a 2 s. co m if (inputFlashMap != null) { Object val = inputFlashMap.get(parameterKey); if (val != null) { return String.valueOf(val); } } return null; }
From source file:eionet.gdem.web.struts.remoteapi.ConvertJson2XmlAction.java
/** * The purpose of this action is to execute <code>Json</code> static methods to convert json string or URL to XML format. The * method expects either url or json parameters. *///from w w w .j av a 2s . co m @Override public ActionForward execute(ActionMapping map, ActionForm actionForm, HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException { String jsonParam = null; Map params = request.getParameterMap(); try { // parse request parameters if (params.containsKey(JSON_PARAM_NAME)) { jsonParam = ((String[]) params.get(JSON_PARAM_NAME))[0]; } if (Utils.isNullStr(jsonParam)) { throw new GDEMException("Missing request parameter: " + JSON_PARAM_NAME); } String xml = ""; if (jsonParam.startsWith("http:")) { // append other parameters to service Url if (params.size() > 1) { jsonParam = getJsonServiceUrl(jsonParam, params); } xml = Json.jsonRequest2xmlString(jsonParam); } else { xml = Json.jsonString2xml(jsonParam); } // set response properties httpServletResponse.setContentType("text/xml"); httpServletResponse.setCharacterEncoding("UTF-8"); httpServletResponse.setContentLength(xml.length()); // write data into response httpServletResponse.getOutputStream().write(xml.getBytes()); } catch (GDEMException ge) { ge.printStackTrace(); LOGGER.error("Unable to convert JSON to XML. " + ge.toString()); throw new ServletException(ge); } catch (Exception e) { e.printStackTrace(); LOGGER.error("Unable to convert JSON to XML. "); throw new ServletException(e); } finally { try { httpServletResponse.getOutputStream().close(); httpServletResponse.getOutputStream().flush(); } catch (IOException ioe) { ioe.printStackTrace(); throw new ServletException(ioe); } } // Do nothing, then response is already sent. return null; }
From source file:edu.mayo.cts2.framework.webapp.rest.filter.jsonp.JsonpCallbackFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new UnspecifiedCts2Exception("ServletRequest expected to be of type HttpServletRequest"); }//from w w w .j ava2 s . co m if (!(response instanceof HttpServletResponse)) { throw new UnspecifiedCts2Exception("ServletResponse expected to be of type HttpServletResponse"); } HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; @SuppressWarnings("unchecked") Map<String, String[]> parms = httpRequest.getParameterMap(); if (parms.containsKey("callback")) { if (log.isDebugEnabled()) { log.debug("Wrapping response with JSONP callback '" + parms.get("callback")[0] + "'"); } OutputStream out = httpResponse.getOutputStream(); GenericResponseWrapper wrapper = new GenericResponseWrapper(httpResponse); chain.doFilter(request, wrapper); out.write(new String(parms.get("callback")[0] + "(").getBytes()); out.write(wrapper.getData()); out.write(new String(");").getBytes()); wrapper.setContentType("text/javascript;charset=UTF-8"); out.close(); } else { chain.doFilter(request, response); } }
From source file:productClass.java
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Set<String> keySet = request.getParameterMap().keySet(); try (PrintWriter out = response.getWriter()) { Connection conn = getConnection(); if (keySet.contains("productID") && keySet.contains("name") && keySet.contains("description") && keySet.contains("quantity")) { PreparedStatement pstmt = conn.prepareStatement("UPDATE product SET name='" + request.getParameter("name") + "',`description`='" + request.getParameter("description") + "',quantity=" + request.getParameter("quantity") + " WHERE `productID`=" + request.getParameter("productID")); try { pstmt.executeUpdate();/*from w w w.j a v a2s . co m*/ doGet(request, response); //shows updated row } catch (SQLException ex) { Logger.getLogger(productClass.class.getName()).log(Level.SEVERE, null, ex); out.println("Error putting values."); } } else { out.println("Error: Not enough data to update"); } } catch (SQLException ex) { Logger.getLogger(productClass.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:productClass.java
/** * Handles the HTTP <code>POST</code> method. * * //from www. j ava 2 s .com * Insertion of values into the database connection * * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Set<String> keySet = request.getParameterMap().keySet(); try (PrintWriter out = response.getWriter()) { Connection conn = getConnection(); if (keySet.contains("name") && keySet.contains("description") && keySet.contains("quantity")) { PreparedStatement pstmt = conn.prepareStatement( "INSERT INTO product(productID, name, description, quantity) " + "VALUES (null, '" + request.getParameter("name") + "', '" + request.getParameter("description") + "', " + request.getParameter("quantity") + ");"); try { pstmt.executeUpdate(); request.getParameter("productID"); doGet(request, response); } catch (SQLException ex) { Logger.getLogger(productClass.class.getName()).log(Level.SEVERE, null, ex); out.println("Data inserted Error while retriving data."); } } else { out.println("Error: Not enough data to input"); } } catch (SQLException ex) { Logger.getLogger(productClass.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.groupbuy.plugin.unionpay.UnionpayPlugin.java
@SuppressWarnings("unchecked") @Override/*from w w w . j ava 2 s .c o m*/ public boolean verifyNotify(String sn, NotifyMethod notifyMethod, HttpServletRequest request) { PluginConfig pluginConfig = getPluginConfig(); Payment payment = getPayment(sn); if (generateSign(request.getParameterMap()).equals(request.getParameter("signature")) && pluginConfig.getAttribute("partner").equals(request.getParameter("merId")) && sn.equals(request.getParameter("orderNumber")) && CURRENCY.equals(request.getParameter("orderCurrency")) && "00".equals(request.getParameter("respCode")) && payment.getAmount().multiply(new BigDecimal(100)) .compareTo(new BigDecimal(request.getParameter("orderAmount"))) == 0) { Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("version", "1.0.0"); parameterMap.put("charset", "UTF-8"); parameterMap.put("transType", "01"); parameterMap.put("merId", pluginConfig.getAttribute("partner")); parameterMap.put("orderNumber", sn); parameterMap.put("orderTime", new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); parameterMap.put("merReserved", ""); parameterMap.put("signMethod", "MD5"); parameterMap.put("signature", generateSign(parameterMap)); String result = post("https://unionpaysecure.com/api/Query.action", parameterMap); if (ArrayUtils.contains(result.split("&"), "respCode=00")) { return true; } } return false; }