Example usage for javax.servlet.http HttpServletRequest getParameterValues

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

Introduction

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

Prototype

public String[] getParameterValues(String name);

Source Link

Document

Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

Usage

From source file:biblivre3.z3950.JsonZ3950Handler.java

private List<Z3950ServerDTO> readServers(final HttpServletRequest request) {
    final List<Z3950ServerDTO> serverList = new ArrayList<Z3950ServerDTO>();

    String[] serverIds = request.getParameterValues("serverIds");
    if (serverIds == null || serverIds.length == 0) {
        return serverList;
    }/*from www.  j  a  v a2  s.  c o  m*/

    Z3950BO serverBo = new Z3950BO();
    for (String id : serverIds) {
        serverList.add(serverBo.findById(id));
    }

    return serverList;
}

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());//from   w  w w. j  av  a 2s  .  co 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:APIRequest.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //2. Merchant server makes an api request to the snap backend to get the SNAP_TOKEN
    //initialize settings.
    response.setHeader("Accept", "application/json");
    response.setContentType("application/json");
    response.setHeader("Authorization", Base64.getEncoder().encodeToString((serverKey + ":").getBytes()));

    String orderID = request.getParameterValues("gross_amount")[0];
    int grossAmount = Integer.parseInt(request.getParameterValues("gross_amount")[0]);
    //dummy data/*from   www . j av a 2 s.c o  m*/
    orderID = "Testing Order-01";
    grossAmount = 150000;

    //JSON object
    JSONObject jso = new JSONObject();
    JSONObject transactionDetails = new JSONObject();
    try {
        transactionDetails.put("order_id", orderID);
        transactionDetails.put("gross_amount", grossAmount);
        jso.put("transaction_details", transactionDetails);
    } catch (JSONException ex) {
        Logger.getLogger(APIRequest.class.getName()).log(Level.SEVERE, null, ex);
    }
    // send the jso to the server.
    response.getWriter().write(jso.toString());
    //3. Snap backend responds to the api call with the SNAP_TOKEN
}

From source file:org.openmrs.module.metadatasharing.web.controller.ExportController.java

@RequestMapping(value = SELECT_ITEMS_PATH, method = RequestMethod.POST)
public String selectItems(@ModelAttribute(PACKAGE_ITEMS) PackageItems packageItems, String type,
        HttpServletRequest request) {
    String[] addUuids = request.getParameterValues("addUuids");
    String[] removeUuids = request.getParameterValues("removeUuids");

    if (addUuids == null) {
        addUuids = new String[0];
    }/*from  ww  w  . java 2  s  . c  o  m*/
    if (removeUuids == null) {
        removeUuids = new String[0];
    }

    Set<Item> items = packageItems.getItems().get(type);

    for (String addUuid : addUuids) {
        Object metadata = Handler.getItemByUuid(Handler.getRegisteredClass(type), addUuid);
        if (metadata != null) {
            if (items == null) {
                items = new HashSet<Item>();
                packageItems.getItems().put(type, items);
            }
            items.add(Item.valueOf(metadata));
        }
    }

    if (items != null) {
        for (String removeUuid : removeUuids) {
            Object metadata = Handler.getItemByUuid(Handler.getRegisteredClass(type), removeUuid);
            if (metadata != null) {
                items.remove(Item.valueOf(metadata));
            }
        }

        if (items.size() == 0) {
            packageItems.getItems().remove(type);
            packageItems.getCompleteTypes().remove(type);
        } else {
            int allItems = Handler.getItemsCount(Handler.getRegisteredClass(type), true, null);
            if (items.size() == allItems) {
                packageItems.getCompleteTypes().add(type);
            } else {
                packageItems.getCompleteTypes().remove(type);
            }
        }
    }

    return WebUtils.redirect(EDIT_PATH);
}

From source file:com.krawler.br.spring.RConverterImpl.java

private Object getParam(HttpServletRequest request, String key, OperationParameter ap) throws ProcessException {
    ModuleDefinition md = mb.getModuleDefinition(ap.getType());
    String[] params = request.getParameterValues(key);

    List l = new ArrayList();
    if (params != null) {
        for (int i = 0; i < params.length; i++) {
            l.add(getValue(params[i], md));
        }//from ww  w.j av  a  2 s.c  om
    }
    return convertToMultiType(l, ap.getMulti(), ap.getType());
}

From source file:fr.paris.lutece.plugins.workflow.modules.assignment.web.AssignmentTaskComponent.java

/**
 * {@inheritDoc}//from  w w  w . j a v a  2s.  com
 */
@Override
public String doValidateTask(int nIdResource, String strResourceType, HttpServletRequest request, Locale locale,
        ITask task) {
    String strError = StringUtils.EMPTY;
    String[] tabWorkgroups = request.getParameterValues(PARAMETER_WORKGROUPS + "_" + task.getId());
    TaskAssignmentConfig config = this.getTaskConfigService().findByPrimaryKey(task.getId());

    if (config == null) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_CONFIGURATION_FOR_TASK_ASSIGNMENT,
                AdminMessage.TYPE_STOP);
    }

    if ((tabWorkgroups == null) || (tabWorkgroups.length == 0)) {
        strError = config.getTitle();
    }

    if (StringUtils.isNotBlank(strError)) {
        Object[] tabRequiredFields = { strError };

        return AdminMessageService.getMessageUrl(request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
                AdminMessage.TYPE_STOP);
    }

    return null;
}

From source file:azkaban.web.pages.IndexServlet.java

private String scheduleJobs(AzkabanApplication app, HttpServletRequest req, HttpServletResponse resp)
        throws IOException, ServletException {
    String[] jobNames = req.getParameterValues("jobs");
    if (!hasParam(req, "jobs")) {
        addError(req, "You must select at least one job to run.");
        return "";
    }/*  w  w  w . java 2 s  .  c o  m*/

    if (hasParam(req, "flow_now")) {
        if (jobNames.length > 1) {
            addError(req, "Can only run flow instance on one job.");
            return "";
        }

        String jobName = jobNames[0];
        JobManager jobManager = app.getJobManager();
        JobDescriptor descriptor = jobManager.getJobDescriptor(jobName);
        if (descriptor == null) {
            addError(req, "Can only run flow instance on one job.");
            return "";
        } else {
            return req.getContextPath() + "/flow?job_id=" + jobName;
        }
    } else {
        for (String job : jobNames) {
            if (hasParam(req, "schedule")) {
                int hour = getIntParam(req, "hour");
                int minutes = getIntParam(req, "minutes");
                boolean isPm = getParam(req, "am_pm").equalsIgnoreCase("pm");
                String scheduledDate = req.getParameter("date");
                DateTime day = null;
                if (scheduledDate == null || scheduledDate.trim().length() == 0) {
                    day = new LocalDateTime().toDateTime();
                } else {
                    try {
                        day = DateTimeFormat.forPattern("MM-dd-yyyy").parseDateTime(scheduledDate);
                    } catch (IllegalArgumentException e) {
                        addError(req, "Invalid date: '" + scheduledDate + "'");
                        return "";
                    }
                }

                ReadablePeriod thePeriod = null;
                if (hasParam(req, "is_recurring"))
                    thePeriod = parsePeriod(req);

                if (isPm && hour < 12)
                    hour += 12;
                hour %= 24;

                app.getScheduleManager().schedule(job,
                        day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(0), thePeriod,
                        false);

                addMessage(req, job + " scheduled.");
            } else if (hasParam(req, "schedule_trigger")) {
                String topic = getParam(req, "topic");

                HashMap<String, String> criteria = new HashMap<String, String>();

                for (int i = 0;; i++) {
                    String key = req.getParameter("key" + i);
                    String val = req.getParameter("val" + i);
                    if (key == null || val == null)
                        break;
                    if (key.length() > 0)
                        criteria.put(key, val);
                }

                String group = getParam(req, "group_id");
                int startHour = getIntParam(req, "start_hour");
                boolean startIsPm = getParam(req, "start_am_pm").equalsIgnoreCase("pm");
                int stopHour = getIntParam(req, "stop_hour");
                if (startIsPm) {
                    startHour += 12;
                    startHour %= 24;
                }
                boolean stopIsPm = getParam(req, "stop_am_pm").equalsIgnoreCase("pm");
                if (stopIsPm) {
                    stopHour += 12;
                    stopHour %= 24;
                }

                app.getScheduleManager().schedule(job, topic, criteria, group, startHour, stopHour, false); //with dependencies.

                addMessage(req, topic + " scheduled.");

            } else if (hasParam(req, "run_now")) {
                boolean ignoreDeps = !hasParam(req, "include_deps");
                try {
                    app.getJobExecutorManager().execute(job, ignoreDeps);
                } catch (JobExecutionException e) {
                    addError(req, e.getMessage());
                    return "";
                }
                addMessage(req, "Running " + job);
            } else {
                addError(req, "Neither run_now nor schedule param is set.");
            }
        }
        return "";
    }

}

From source file:com.weitaomi.systemconfig.filter.LoggingFilter.java

private String getPostParamsStr(HttpServletRequest request) {
    StringBuffer sb = new StringBuffer();
    sb.append("{");

    Enumeration<String> parameterNames = request.getParameterNames();

    while (parameterNames.hasMoreElements()) {
        String name = parameterNames.nextElement();
        sb.append("\"").append(name).append("\"").append(":")
                .append(StringUtil.stringArrayToStringWithQuot(request.getParameterValues(name))).append(",");
    }/*w w w. j  ava2 s . c  o m*/
    if (sb.length() > 1) {
        sb.deleteCharAt(sb.length() - 1);
    }
    sb.append("}");

    return sb.toString();
}

From source file:nl.minbzk.dwr.zoeken.enricher.aci.ImportController.java

/**
 * Resolve a given parameter value from either a given map or the request.
 * /*from   ww w .  ja  v  a2  s  .  com*/
 * @param request
 * @param parameters
 * @param parameter
 * @return String
 */
private String[] resolveParameterValues(final HttpServletRequest request,
        final Map<String, String[]> parameters, final String parameter) {
    if (parameters != null && parameters.containsKey(parameter))
        return parameters.get(parameter);
    else
        return request.getParameterValues(parameter);
}

From source file:gov.nih.nci.cabig.caaers.web.study.SolicitedAdverseEventTab.java

/**
 * Will be called, when you delete an epoch on the screen.
 * @param request//from   w w  w  . j a va2s .co  m
 * @param command
 * @param error
 * @return
 */
public ModelAndView deleteEpoch(HttpServletRequest request, Object command, Errors error) {
    Study study = ((StudyCommand) command).getStudy();
    // the list of all epochs on the page (before deleting) except the # of the one to delete
    String[] epoch_ids = request.getParameterValues("epoch_id");
    retainOnlyTheseEpochsInStudy(request, study, epoch_ids);
    return new ModelAndView(getAjaxViewName(request), new java.util.HashMap());
}