List of usage examples for javax.servlet.http HttpServletRequest getParameterNames
public Enumeration<String> getParameterNames();
Enumeration
of String
objects containing the names of the parameters contained in this request. From source file:ProductServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try (PrintWriter out = response.getWriter()) { Connection conn = getConnection(); Statement stmt = conn.createStatement(); if (!request.getParameterNames().hasMoreElements()) { out.println(getResults("SELECT * FROM product")); } else {//from w w w . ja v a2 s . co m if (request.getParameter("productID") == null) { out.println(getResults("SELECT * FROM product ORDER BY productID DESC LIMIT 1")); } else { int id = Integer.parseInt(request.getParameter("productID")); out.println(getResults("SELECT * FROM product WHERE productID = ?", String.valueOf(id))); } } } catch (SQLException ex) { Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.purdue.cybercenter.dm.web.TermController.java
private String listTerms(HttpServletRequest request, HttpServletResponse response, String type) { Integer[] ia = WebHelper.getDojoGridPaginationInfo(request); Integer firstResult = ia[0];/*from w ww . j av a 2s .c o m*/ Integer lastResult = ia[1]; Map.Entry<String, String> orderBy = WebHelper.getDojoJsonRestStoreOrderBy(request.getParameterNames()); Map<String, Object> where = WebHelper.FromJsonToFilterClass(request.getParameter("filter")); List<edu.purdue.cybercenter.dm.domain.Term> dbTerms = domainObjectService.findEntries(firstResult, lastResult - firstResult + 1, orderBy, where, edu.purdue.cybercenter.dm.domain.Term.class); Integer totalCount = domainObjectService.countEntries(where, edu.purdue.cybercenter.dm.domain.Term.class) .intValue(); WebHelper.setDojoGridPaginationInfo(firstResult, lastResult, totalCount, response); List<Term> terms = termService.dbTermsToTerms(dbTerms); List<TermDto> termDtos = new ArrayList<>(); for (Term term : terms) { term.setType(type); TermDto termDto = TermMapper.INSTANCE.toTermDto(term); termDtos.add(termDto); } return Helper.deepSerialize(termDtos); }
From source file:com.icesoft.faces.webapp.http.servlet.ServletEnvironmentRequest.java
public void setParameters(HttpServletRequest request) { parameters = new HashMap(); Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String name = (String) parameterNames.nextElement(); parameters.put(name, request.getParameterValues(name)); }/*from w w w .j a v a2 s . co m*/ }
From source file:com.wabacus.util.Tools.java
public static String getRequestNameAndValueAsString(HttpServletRequest request) { if (request == null) { return ""; }//from www. ja va2 s . co m Enumeration names = request.getParameterNames(); if (names == null) { return ""; } String name = ""; String value = ""; StringBuffer sbuffer = new StringBuffer(); while (names.hasMoreElements()) { name = (String) names.nextElement(); value = getRequestValue(request, name, ""); if (value.trim().equals("")) { continue; } sbuffer.append(name + "=" + value + "&"); } String temp = sbuffer.toString().trim(); if (temp.endsWith("&")) { temp = temp.substring(0, temp.length() - 1); } return temp; }
From source file:net.java.javamoney.examples.tradingapp.web.PortfolioController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); String m = null;//from w w w .ja v a 2 s .com Object o; Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { o = e.nextElement(); //logger.info("Param: " + o); if (String.valueOf(o).equals(MODEL)) { o = request.getParameter(MODEL); if (o instanceof Map) { //logger.info("It's a Map"); model = (Map) o; } } else if (String.valueOf(o).equals(MARKET)) { m = request.getParameter(MARKET); } } if (m != null && m.length() > 0) { String mDetails = this.market.getKnownMarkets().get(m); logger.info("Market: " + m + "=" + mDetails); market.setSymbol(m); //model.put(MARKET, m); String cSymbol = null; String mName = null; StringTokenizer st = new StringTokenizer(mDetails, ";"); while (st.hasMoreElements()) { if (mName == null) { mName = st.nextToken(); } else { if (cSymbol == null) { cSymbol = st.nextToken(); } } } if (mName != null) { market.setName(mName); } if (cSymbol != null) { Currency curr = new Currency(cSymbol); // TODO retrieve this from Yahoo Service similar to quotes, or 354 style ExchangeRateProvider Object oRate = market.getCurrencyExchangeRates().get(cSymbol); if (oRate != null) { Number exchangeRate; if (oRate instanceof Number) { exchangeRate = (Number) oRate; } else { try { exchangeRate = Double.parseDouble(String.valueOf(oRate)); } catch (NumberFormatException nfe) { logger.warn("Error during currency conversion", nfe); exchangeRate = 0; } } logger.info(exchangeRate); curr.setExchangeRate(exchangeRate.doubleValue()); } else { logger.warn("Could not find exchange rate for " + curr); curr.setExchangeRate(0); // TODO kind of dodgy, should throw exception or something? } //curr.setExchangeRate(1.4); labelCurrency(cSymbol, curr); //Currency.setReferenceCurrency(curr); portfolio.setCurrency(curr); // TODO portfolio should directly store market! market.setCurrency(curr); } } List<PortfolioItemBean> portfolioItems = getPortfolioItems(); model.put(MARKET, market); model.put("currency", portfolio.getCurrency()); model.put("cash", portfolio.getCash() + ""); model.put("amount", portfolio.getAmount()); model.put("amountLocal", portfolio.getAmount().to(portfolio.getCurrency())); model.put("portfolioItems", portfolioItems); return new ModelAndView(PORTFOLIO, MODEL, model); }
From source file:com.mockey.ui.JsonSchemaValidateServlet.java
@Override public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final Set<String> params = Sets.newHashSet(); final Enumeration<String> enumeration = req.getParameterNames(); // FIXME: no duplicates, it seems, but I cannot find the spec which // guarantees that while (enumeration.hasMoreElements()) params.add(enumeration.nextElement()); // We have required parameters if (!params.containsAll(ValidateRequest.REQUIRED_PARAMS)) { logger.warn("Missing parameters! Someone using me as a web service?"); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing parameters"); return;/* w w w . j a v a2 s . c o m*/ } // We don't want extraneous parameters params.removeAll(ValidateRequest.VALID_PARAMS); if (!params.isEmpty()) { logger.warn("Invalid parameters! Someone using me as a web service?"); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid parameters"); return; } final String rawSchema = req.getParameter(ValidateRequest.SCHEMA); final String data = req.getParameter(ValidateRequest.DATA); // Set correct content type resp.setContentType(MediaType.JSON_UTF_8.toString()); final boolean useV3 = Boolean.parseBoolean(req.getParameter(ValidateRequest.USE_V3)); final boolean useId = Boolean.parseBoolean(req.getParameter(ValidateRequest.USE_ID)); final JsonNode ret = JsonSchemaUtil.buildResult(rawSchema, data, useV3, useId); final OutputStream out = resp.getOutputStream(); try { out.write(ret.toString().getBytes(Charset.forName("UTF-8"))); out.flush(); } finally { Closeables.closeQuietly(out); } }
From source file:org.okj.commons.web.json.interceptor.JSONOutputterInterceptor.java
/** * JsonResponse// w w w . ja v a 2 s . c o m * @param handlerMethods * @param request * @return */ protected Method findResolvedMethod(Set<Method> handlerMethods, HttpServletRequest request) { //method1?Method for (Enumeration<String> names = request.getParameterNames(); names.hasMoreElements();) { // String name = names.nextElement(); String value = request.getParameter(name); //method for (Method method : handlerMethods) { //JsonResponse JsonResponse annotation = AnnotationUtils.findAnnotation(method, JsonResponse.class); if (isMatch(annotation, name + "=" + value)) { return method; } } //end for } //end for return null; }
From source file:net.riezebos.thoth.servlets.ServletBase.java
protected Map<String, Object> getParameters(HttpServletRequest request) throws ServletException { Map<String, Object> result = new HashMap<>(); Enumeration<String> parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String key = parameterNames.nextElement(); result.put(key, request.getParameter(key)); }//from w w w .j a va 2 s . com String contextName = getContext(request); Skin skin = getSkin(request); String skinBase = null; if (skin != null) { String baseUrl = ThothUtil.prefix(skin.getBaseUrl(), "/"); if (skin.isFromClassPath()) { skinBase = ContentManager.NATIVERESOURCES + baseUrl; } else { skinBase = baseUrl; } skinBase = request.getContextPath() + ThothUtil.prefix(skinBase, "/"); } Configuration configuration = getConfiguration(); Date now = new Date(); String path = ThothUtil.prefix(getPath(request), "/"); String contextUrl = getContextUrl(request); String documentUri = ThothUtil.suffix(contextUrl, "/") + ThothUtil.stripPrefix(path, "/"); result.put(Renderer.CONTEXT_PARAMETER, contextName); result.put(Renderer.SKINBASE_PARAMETER, skinBase); result.put(Renderer.CONTEXTURL_PARAMETER, contextUrl); result.put(Renderer.CONTEXTPATH_PARAMETER, request.getContextPath()); result.put(Renderer.PATH_PARAMETER, path); result.put(Renderer.URI_PARAMETER, documentUri); result.put(Renderer.TITLE_PARAMETER, getTitle(request)); result.put(Renderer.SKIN, skin == null ? null : skin.getName()); result.put(Renderer.TODAY, configuration.getDateFormat().format(now)); result.put(Renderer.NOW, configuration.getTimestampFormat().format(now)); result.put(Renderer.OUTPUT_FORMATS, configuration.getOutputFormats()); result.put(Renderer.REFRESH_PARAMETER, getRefreshTimestamp(contextName)); result.put(Renderer.SERVERNAME, configuration.getServerName()); Set<String> permissions = new HashSet<>(); result.put(Renderer.LOGGED_IN, isLoggedIn(request)); Identity identity = getCurrentIdentity(request); if (identity != null) { result.put(Renderer.IDENTITY, identity.getIdentifier()); result.put(Renderer.USER_FULL_NAME, identity.getDescription()); for (Permission permission : identity.getEffectivePermissions()) permissions.add(String.valueOf(permission)); } else { result.put(Renderer.IDENTITY, null); } result.put(Renderer.PERMISSIONS, permissions); return result; }
From source file:gov.nih.nci.system.web.struts.action.CreateAction.java
private Object prepareObject(HttpServletRequest request) throws NumberFormatException, Exception { StringBuilder sb = new StringBuilder(); Enumeration<String> parameters = request.getParameterNames(); Object instance = null;//from w w w. ja v a 2 s. com try { Class klass = Class.forName(selectedDomain); instance = klass.newInstance(); while (parameters.hasMoreElements()) { String parameterName = (String) parameters.nextElement(); if (!parameterName.equals("klassName") && !parameterName.equals("searchObj") && !parameterName.equals("BtnSearch") && !parameterName.equals("username") && !parameterName.equals("password") && !parameterName.equals("selectedDomain")) { String parameterValue = (request.getParameter(parameterName)).trim(); setParameterValue(klass, instance, parameterName, parameterValue); } } } catch (NumberFormatException e) { throw e; } catch (Exception e) { throw e; } return instance; }
From source file:com.swdouglass.joid.server.OpenIdServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringBuilder sb = new StringBuilder(); Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String[] values = request.getParameterValues(name); if (values.length == 0) { throw new IOException("Empty value not allowed: " + name + " has no value"); }//from w w w . j ava 2 s.c om try { sb.append(URLEncoder.encode(name, "UTF-8") + "=" + URLEncoder.encode(values[0], "UTF-8")); } catch (UnsupportedEncodingException ex) { throw new IOException(ex.toString()); } if (e.hasMoreElements()) { sb.append("&"); } } doQuery(sb.toString(), request, response); }