Example usage for javax.servlet.http HttpServletRequest getParameterNames

List of usage examples for javax.servlet.http HttpServletRequest getParameterNames

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterNames.

Prototype

public Enumeration<String> getParameterNames();

Source Link

Document

Returns an Enumeration of String objects containing the names of the parameters contained in this request.

Usage

From source file:org.apache.ofbiz.base.util.UtilHttp.java

/**
 * Put request parameters in request object as attributes.
 * @param request/*from  w  ww.  jav  a  2 s.  c o  m*/
 */
public static void parametersToAttributes(HttpServletRequest request) {
    java.util.Enumeration<String> e = UtilGenerics.cast(request.getParameterNames());
    while (e.hasMoreElements()) {
        String name = e.nextElement();
        request.setAttribute(name, request.getParameter(name));
    }
}

From source file:com.jaspersoft.jasperserver.rest.utils.Utils.java

/**
 * Look for parameters provided by the client.
 *
 * @param req  HttpServletRequest/*w ww  . j a v  a  2  s.c om*/
 * @return Map&lt;String,Object&gt;
 */
public Map<String, Object> extractParameters(HttpServletRequest req) {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Enumeration penum = req.getParameterNames();
    while (penum.hasMoreElements()) {
        String pname = (String) penum.nextElement();
        if (pname.startsWith("P_")) {
            parameters.put(pname.substring(2), req.getParameter(pname));
        } else if (pname.startsWith("PL_")) {
            parameters.put(pname.substring(3), Arrays.asList(req.getParameterValues(pname)));
        }
    }
    return parameters;
}

From source file:alpha.portal.webapp.controller.CardFormController.java

/**
 * handles the case, if the user clicks on one of the buttons.
 * //from   ww  w.j a  va2  s.  co  m
 * @param myCard
 *            the my card
 * @param errors
 *            the errors
 * @param request
 *            the request
 * @param response
 *            the response
 * @return success view
 * @throws Exception
 *             the exception
 */
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public String onSubmit(final AlphaCard myCard, final BindingResult errors, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {

    this.log.fatal("This fallback Method should not be called");

    final Enumeration params = request.getParameterNames();
    while (params.hasMoreElements()) {
        this.log.error(params.nextElement().toString());
    }

    return "redirect:/caseform?caseId=" + myCard.getAlphaCardIdentifier().getCaseId();
}

From source file:classes.Product.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request// w ww .  j av  a 2s.  c o m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occuresultSet
 * @throws IOException if an I/O error occuresultSet
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    // to indicate content type
    response.setHeader("Content-Type", "text/plain-text");

    try {
        //getting response from user
        PrintWriter printer = response.getWriter();

        String query = "SELECT * FROM products;";

        if (!request.getParameterNames().hasMoreElements()) {
            printer.println(getResult(query));
        } else {
            int id = Integer.parseInt(request.getParameter("productId"));
            printer.println(getResult("SELECT * FROM products WHERE Product_id= ?", String.valueOf(id)));
        }

    } catch (IOException ex) {
        System.err.println("Input printer Exception: " + ex.getMessage());
    }
}

From source file:com.concursive.connect.web.portal.PortalURLParserImpl.java

/**
 * Parse a servlet request to a portal URL.
 *
 * @param request the servlet request to parse.
 * @return the portal URL./* ww  w  . j ava2  s  . c o m*/
 */
public PortalURL parse(HttpServletRequest request) {

    LOG.debug("Parsing URL: " + request.getRequestURI());

    if (LOG.isDebugEnabled()) {
        Enumeration params = request.getParameterNames();
        while (params.hasMoreElements()) {
            String param = (String) params.nextElement();
            LOG.debug("  parameter: " + param + "=" + request.getParameter(param));
        }
    }

    StringBuffer url = new StringBuffer();
    if (request.getParameterMap() != null) {
        // To construct the base URL for the portal, append the allowed portal URL
        // parameters that are specified by the portal manager
        ArrayList allowedPortalParams = (ArrayList) request.getAttribute(ALLOWED_PORTAL_PARAMETERS);
        if (allowedPortalParams != null) {
            Iterator i = allowedPortalParams.iterator();
            while (i.hasNext()) {
                String paramName = (String) i.next();
                String paramValue = request.getParameter(paramName);
                if (paramValue != null) {
                    // @note TEST TEST TEST
                    //appendParameter(url, paramName + "=" + paramValue);
                    appendParameter(url, paramName + "=" + StringUtils.encodeUrl(paramValue));
                }
            }
        }
    }

    String servletName = request.getServletPath() + url.toString();

    // Construct portal URL using info retrieved from servlet request
    String contextPath = request.getContextPath();
    LOG.debug("contextPath: " + contextPath);
    PortalURL portalURL = new RelativePortalURLImpl(contextPath, servletName, getParser());

    // Action window definition: portalURL.setActionWindow()
    String portletAction = request.getParameter("portletAction");
    if (portletAction != null && portletAction.startsWith(PREFIX + ACTION)) {
        LOG.debug("found action");
        portalURL.setActionWindow(decodeControlParameter(portletAction)[0]);
        portalURL.setRenderPath(contextPath + ".");
    }

    // Window state definition: portalURL.setWindowState()
    String portletWindowState = null;
    int windowStateCount = 0;
    while ((portletWindowState = request.getParameter("portletWindowState" + (++windowStateCount))) != null) {
        String[] decoded = decodeControlParameter(portletWindowState);
        portalURL.setWindowState(decoded[0], new WindowState(decoded[1]));
    }

    // Portlet mode definition: portalURL.setPortletMode()
    String portletMode = request.getParameter("portletMode");
    if (portletMode != null) {
        String[] decoded = decodeControlParameter(portletMode);
        portalURL.setPortletMode(decoded[0], new PortletMode(decoded[1]));
    }

    // Portal URL parameter: portalURL.addParameter()
    Enumeration params = request.getParameterNames();
    while (params.hasMoreElements()) {
        String parameter = (String) params.nextElement();
        if (parameter.startsWith(PREFIX + RENDER_PARAM)) {
            String value = request.getParameter(parameter);
            LOG.debug("parameter: " + parameter);
            // @note TEST TEST TEST
            //portalURL.addParameter(decodeParameter(parameter, value));
            portalURL.addParameter(decodeParameter(parameter, StringUtils.encodeUrl(value)));
        }
    }

    // Return the portal URL.
    return portalURL;
}

From source file:io.kahu.hawaii.rest.AbstractController.java

protected RequestLogBuilder requestLog() {

    String method = new Throwable().getStackTrace()[1].getMethodName();
    String type = logTypePrefix + "." + method;
    RequestLogBuilder builder = new RequestLogBuilder(logManager, type);

    try {/*from   w  w  w . j a v  a  2  s . c om*/
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = sra.getRequest();

        // path variables
        Map<String, String> pathVariables = (Map<String, String>) request
                .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        if (pathVariables != null) {
            for (Map.Entry<String, String> entry : pathVariables.entrySet()) {
                builder.param(entry.getKey(), entry.getValue());
            }
        }

        // request parameters
        Enumeration<?> requestParameters = request.getParameterNames();
        while (requestParameters.hasMoreElements()) {
            String key = (String) requestParameters.nextElement();
            String[] values = request.getParameterValues(key);
            builder.param(key, values);
        }

    } catch (Throwable t) {
        logManager.warn(CoreLoggers.SERVER, "Unable to log request", t);
        // ignore
    }
    return builder.excludeParam("_");
}

From source file:cn.itcast.bbs.controller.BbsServlet.java

private void editTopic(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {//  w  w w  .  j  a v a  2s  .  c  om
        Topic topic = new Topic();
        Enumeration<String> enums = request.getParameterNames();
        while (enums.hasMoreElements()) {
            String key = enums.nextElement();
            if (key.equals("method") || key.equals("typeId")) {
                continue;
            }
            String[] value = request.getParameterValues(key);
            BeanUtils.setProperty(topic, key, value);
        }
        service.updateTopic(topic);
        int typeId = Integer.parseInt(request.getParameter("typeId"));
        response.sendRedirect(request.getContextPath() + "/BbsServlet?method=showAllTopic&typeId=" + typeId);
    } catch (Exception e) {
        e.printStackTrace();
        request.setAttribute("message", "");
        request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response);
    }

}

From source file:jp.mathes.databaseWiki.web.DbwServlet.java

@SuppressWarnings("unchecked")
private void redirect(final String baseURL, final HttpServletRequest req, final HttpServletResponse resp,
        final String db, final String table, String name, final boolean withParameters) throws IOException {
    name = URLEncoder.encode(name, "UTF-8");
    StringBuilder paramStr = new StringBuilder();
    if (withParameters) {
        for (String paramName : Collections.list((Enumeration<String>) req.getParameterNames())) {
            if (paramName.startsWith("_") || paramName.equals("name")) {
                continue;
            }//from   w w  w  .j  a  v a2  s .  c  om
            for (String value : req.getParameterValues(paramName)) {
                paramStr.append(paramName).append("=").append(value).append("&");
            }
        }
    }
    if (paramStr.length() > 0) {
        resp.sendRedirect(
                String.format(baseURL + "?%s", req.getContextPath(), db, table, name, paramStr.toString()));
    } else {
        resp.sendRedirect(String.format(baseURL, req.getContextPath(), db, table, name));
    }
}

From source file:com.emc.plants.web.servlets.ShoppingServlet.java

/**
 * Process incoming HTTP POST requests/*from w  ww.  j a  v  a 2  s.co  m*/
 *
 * @param request Object that encapsulates the request to the servlet
 * @param response Object that encapsulates the response from the servlet
 */
public void doPost(javax.servlet.http.HttpServletRequest request,
        javax.servlet.http.HttpServletResponse response) throws ServletException, IOException {
    //sanitize the request parameters to prevent XSS security vulnerability
    Enumeration names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String val = (String) request.getParameter((String) names.nextElement());
        if (!Util.validateString(val)) {
            throw new ServletException(
                    "Invalid input parameter in ShoppingServlet:" + URLEncoder.encode(val, "UTF8"));
        }
    }
    performTask(request, response);
}

From source file:cn.itcast.bbs.controller.BbsServlet.java

private void register(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    User user = new User();
    Enumeration<String> enums = request.getParameterNames();
    try {/*from  www  .  j  a v  a  2  s .c  o  m*/
        while (enums.hasMoreElements()) {
            String name = enums.nextElement();
            if (name.equals("method") || name.equals("checkCode")) {
                continue;
            }
            String[] value = request.getParameterValues(name);
            //System.out.println(name+":"+value[0]);
            BeanUtils.setProperty(user, name, value);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    String checkCode = request.getParameter("checkCode");
    HttpSession session = request.getSession();
    String ideacheckCode = (String) session.getAttribute("checkCode");
    try {
        //???
        if (checkCode.equals(ideacheckCode)) {
            RegisterForm registerForm = new RegisterForm();
            //??????
            if (registerForm.validate(user)) {
                if (service.findUser(user.getUsername()) == null) {
                    if (registerForm.validate2Password(user)) {
                        session.setAttribute("user", user);
                        List<String> usernameList = (List<String>) this.getServletContext()
                                .getAttribute("usernameList");
                        usernameList.add(user.getUsername());
                        service.saveUser(user);
                        request.setAttribute("message", "<font color='red'>??</font>");
                        response.setHeader("Refresh", "2;/my-bbs/");
                        request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
                    } else {
                        //??
                        request.setAttribute("passmessage",
                                "<font color='red'>???</font>");
                        request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
                    }
                } else {
                    //??
                    request.setAttribute("usermessage", "<font color='red'>??</font>");
                    request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
                }
            } else {
                //?????
                request.setAttribute("registerForm", registerForm);
                request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
            }
        } else {
            //???
            request.setAttribute("checkmessage",
                    "<font color='red'>????</font>");
            request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
        }
        request.setAttribute("user", user);
    } catch (Exception e) {
        e.printStackTrace();
        request.setAttribute("message", "");
        request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response);
    }
}