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:com.viseur.control.SearchDevItems.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from w ww.ja  v a 2s.c o  m
 * @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 ServletException, IOException {
    JSONObject obj = new JSONObject();
    try {
        obj.put("success", 0);
    } catch (JSONException ex) {
    }
    Enumeration<String> names = request.getParameterNames();
    String para = names.nextElement();
    String val = request.getParameter(para);
    DeveloperItems itm = new DeveloperItems();
    switch (para) {
    case "lang":
        obj = new JSONObject(itm.getProgrammingLangs(val));
        break;
    case "opsys":
        obj = new JSONObject(itm.getOpSystems(val));
        break;
    case "platform":
        obj = new JSONObject(itm.getPlatforms(val));
        break;
    }
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println(obj);
    }
}

From source file:cz.incad.Kramerius.security.rightscommands.post.Edit.java

@Override
public void doCommand() {
    try {/*w  w  w . jav a  2s . c  o  m*/
        HttpServletRequest req = this.requestProvider.get();
        //Right right = RightsServlet.createRightFromPost(req, rightsManager, userManager, criteriumWrapperFactory);
        Map values = new HashMap();
        Enumeration parameterNames = req.getParameterNames();

        while (parameterNames.hasMoreElements()) {
            String key = (String) parameterNames.nextElement();
            String value = req.getParameter(key);
            SimpleJSONObjects simpleJSONObjects = new SimpleJSONObjects();
            simpleJSONObjects.createMap(key, values, value);
        }

        List affectedObjects = (List) values.get("affectedObjects");
        for (int i = 0; i < affectedObjects.size(); i++) {
            String pid = affectedObjects.get(i).toString();
            editRight((Map) values.get("data"), pid);
        }

    } catch (NumberFormatException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:com.redhat.rhn.frontend.action.channel.ssm.ChildChannelAction.java

/**
 * Processes the submitted parameters to determine which channels are being
 * subscribed, unsubscribed, or ignored. The first two sets will be stored as
 * RhnSets for later usage./*  w  ww  .  j  av  a 2s  .  com*/
 *
 * @param user    user making the request
 * @param request http request to grab the user submitted data from
 */
protected int processList(User user, HttpServletRequest request) {

    List<String> subList = new ArrayList<String>();
    List<String> unsubList = new ArrayList<String>();

    Enumeration<String> names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String aName = names.nextElement();
        String aValue = request.getParameter(aName);
        if ("subscribe".equals(aValue)) {
            subList.add(aName);
        } else if ("unsubscribe".equals(aValue)) {
            unsubList.add(aName);
        }
    }

    storeChannelChanges(user, subList, unsubList);
    return subList.size() + unsubList.size();
}

From source file:com.glaf.core.util.RequestUtils.java

/**
 * request?//from w  ww .jav  a2  s . c o m
 * 
 * @param pRequest
 *            request
 * @param pModel
 *            ?
 * @return 
 * @throws InputInvalidException
 */
public static Object getParameter(HttpServletRequest request, Object object) throws ServletException {
    Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
    Enumeration<?> enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) {
        String paramName = (String) enumeration.nextElement();
        String paramValue = getParameter(request, paramName);
        if (StringUtils.isNotEmpty(paramName) && StringUtils.isNotEmpty(paramValue)) {
            if (paramValue.equalsIgnoreCase("null")) {
                continue;
            }
            dataMap.put(paramName, paramValue);
            if (paramName.toLowerCase().trim().indexOf("date") > 0) {
                try {
                    Date date = DateUtils.toDate(paramValue);
                    dataMap.put(paramName, date);
                } catch (Exception ex) {
                }
            }
        }
    }
    try {
        BeanUtils.populate(object, dataMap);
    } catch (Exception ex) {
        throw new ServletException(ex.getMessage());
    }
    return object;
}

From source file:cz.incad.Kramerius.security.rightscommands.post.Create.java

@Override
public void doCommand() {
    try {/* w  w  w.j  a  v a2  s.c  o m*/
        HttpServletRequest req = this.requestProvider.get();
        //Right right = RightsServlet.createRightFromPost(req, rightsManager, userManager, criteriumWrapperFactory);
        Map values = new HashMap();
        Enumeration parameterNames = req.getParameterNames();

        while (parameterNames.hasMoreElements()) {
            String key = (String) parameterNames.nextElement();
            String value = req.getParameter(key);
            SimpleJSONObjects simpleJSONObjects = new SimpleJSONObjects();
            simpleJSONObjects.createMap(key, values, value);
        }

        List affectedObjects = (List) values.get("affectedObjects");
        for (int i = 0; i < affectedObjects.size(); i++) {
            String pid = affectedObjects.get(i).toString();
            insertRight((Map) values.get("data"), pid);
        }

    } catch (NumberFormatException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:cz.incad.Kramerius.security.rightscommands.post.Delete.java

@Override
public void doCommand() {
    try {//from   w w w  .j  ava 2s. c  om

        HttpServletRequest req = this.requestProvider.get();
        //Right right = RightsServlet.createRightFromPost(req, rightsManager, userManager, criteriumWrapperFactory);
        Map values = new HashMap();
        Enumeration parameterNames = req.getParameterNames();

        while (parameterNames.hasMoreElements()) {
            String key = (String) parameterNames.nextElement();
            String value = req.getParameter(key);
            SimpleJSONObjects simpleJSONObjects = new SimpleJSONObjects();
            simpleJSONObjects.createMap(key, values, value);
        }

        List rightsToDelete = (List) values.get("deletedrights");

        for (int i = 0; i < rightsToDelete.size(); i++) {
            String id = rightsToDelete.get(i).toString();
            deleteRight(Integer.parseInt(id));

        }

    } catch (SQLException e) {
        try {
            this.responseProvider.get().sendError(HttpServletResponse.SC_FORBIDDEN);
        } catch (IOException e1) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    out.println("Query String:");
    out.println(req.getQueryString());//w w  w. j a  va2s . c  o m
    out.println();

    out.println("Request Parameters:");
    Enumeration e = req.getParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String values[] = req.getParameterValues(name);
        if (values != null) {
            for (int i = 0; i < values.length; i++) {
                out.println(name + " (" + i + "): " + values[i]);
            }
        }
    }
}

From source file:com.mb.framework.web.filter.ReqRespLoggerFilter.java

/**
 * /*from w  ww . ja  va  2 s .  c o m*/
 * This method is used for fetching the request method parameters.
 * 
 * @param request
 * @return
 */
@SuppressWarnings("unused")
private Map<String, String> getTypesafeRequestMap(HttpServletRequest request) {

    Map<String, String> typesafeRequestMap = new HashMap<String, String>();

    Enumeration<?> requestParamNames = request.getParameterNames();

    while (requestParamNames.hasMoreElements()) {

        String requestParamName = (String) requestParamNames.nextElement();

        String requestParamValue = request.getParameter(requestParamName);

        typesafeRequestMap.put(requestParamName, requestParamValue);

    }

    return typesafeRequestMap;

}

From source file:cc.aileron.wsgi.request.WsgiRequestParameterFactoryImpl.java

private Map<String, Object> initMap(final HttpServletRequest request) {
    final ArrayList<String> keys = new ArrayList<String>();
    final Enumeration<?> enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) {
        keys.add(enumeration.nextElement().toString());
    }/*from ww w . j  a  va 2 s. co m*/
    final HashMap<String, Object> map = new HashMap<String, Object>();
    for (final String key : keys) {
        final String[] vals = request.getParameterValues(key);
        final Object value;
        if (vals == null) {
            value = null;
        } else {
            value = vals.length == 1 ? vals[0] : new SkipList<String>(vals);
        }
        map.put(key, value);
    }
    return map;
}