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:org.lareferencia.xoai.controller.LROAIDataProvider.java

private Map<String, List<String>> buildParametersMap(HttpServletRequest request) {
    Map<String, List<String>> map = new HashMap<String, List<String>>();
    Enumeration names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String[] values = request.getParameterValues(name);
        map.put(name, asList(values));// www  .  j  av a  2  s.c om
    }
    return map;
}

From source file:org.openmrs.web.controller.form.FieldTypeListController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db//  w  w w.j a v a2  s . c  om
 *
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 *
 * @should display a user friendly error message
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();
    if (Context.isAuthenticated()) {
        String[] fieldTypeList = request.getParameterValues("fieldTypeId");
        FormService fs = Context.getFormService();
        //FieldTypeService rs = new TestFieldTypeService();

        String success = "";
        String error = "";

        MessageSourceAccessor msa = getMessageSourceAccessor();
        String deleted = msa.getMessage("general.deleted");
        String notDeleted = msa.getMessage("general.cannot.delete");
        String textFieldType = msa.getMessage("FieldType.fieldType");
        String noneDeleted = msa.getMessage("FieldType.nonedeleted");
        if (fieldTypeList != null) {
            for (String fieldTypeId : fieldTypeList) {
                //TODO convenience method deleteFieldType(Integer) ??
                try {
                    fs.purgeFieldType(fs.getFieldType(Integer.valueOf(fieldTypeId)));
                    if (!"".equals(success)) {
                        success += "<br/>";
                    }
                    success += textFieldType + " " + fieldTypeId + " " + deleted;
                } catch (APIException e) {
                    log.warn("Error deleting field type", e);
                    if (!"".equals(error)) {
                        error += "<br/>";
                    }
                    error += textFieldType + " " + fieldTypeId + " " + notDeleted;
                } catch (DataIntegrityViolationException e) {
                    log.error("Unable to delete a field type because it is in use. fieldTypeId: " + fieldTypeId,
                            e);
                    httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "FieldType.cannot.delete");
                    return new ModelAndView(new RedirectView(getSuccessView()));
                }
            }
        } else {
            success += noneDeleted;
        }
        view = getSuccessView();
        if (!"".equals(success)) {
            httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success);
        }
        if (!"".equals(error)) {
            httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error);
        }
    }

    return new ModelAndView(new RedirectView(view));
}

From source file:gsn.http.ac.ParameterSet.java

/*************************************************************************************************/

/* constructor for processing parameters of a normal form */
public ParameterSet(HttpServletRequest req) {
    paramset = new Hashtable();
    Enumeration myenum = req.getParameterNames();
    while (myenum.hasMoreElements()) {
        String name = (String) myenum.nextElement();
        String values[] = req.getParameterValues(name);
        if (values != null) {
            if (values.length <= 1) {
                paramset.put(name, req.getParameter(name));

            }// w  w  w.  java 2s .  c  o m
        } else {
            paramset.put(name, req.getParameter(name));

        }
    }
}

From source file:com.example.appengine.autocomplete.ProductNameAutocompleteJSONServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String path = request.getRequestURI();
    if (path.startsWith("/favicon.ico")) {
        return; // ignore the request for favicon.ico
    }/*from  w  w  w  .  jav  a2 s.  co  m*/

    String[] qContents = request.getParameterValues("q");
    if (qContents == null || qContents.length == 0) {
        PrintWriter out = response.getWriter();
        out.println("Invalid usage");
        return;
    }

    String[] queryElements = qContents[0].trim().split("\\s");
    ArrayList<String> inputPrefixes = new ArrayList<String>();
    for (String s : queryElements) {
        if (s.length() >= minimumPrefixSize) {
            if (s.length() > maximumPrefixSize) {
                s = s.substring(0, maximumPrefixSize);
            }
            inputPrefixes.add(s.toLowerCase());
        }
    }
    Collections.sort(inputPrefixes);
    StringBuilder keyBuilder = new StringBuilder();
    for (String prefix : inputPrefixes) {
        keyBuilder.append(prefix + " ");
    }
    String jsonP = null;

    // try to read from cache
    MemcacheService memCache = MemcacheServiceFactory.getMemcacheService();
    memCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
    byte[] key = keyBuilder.toString().trim().getBytes();
    byte[] cacheValue = (byte[]) memCache.get(key);

    if (cacheValue == null) {
        ArrayList<String> suggestions = generateListAutoCompleteSuggestions(inputPrefixes);
        jsonP = outputJSONPFromSuggestions(suggestions);
        memCache.put(key, jsonP.getBytes());
    } else {
        jsonP = new String(cacheValue);
    }

    response.setContentType("application/javascript;charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");

    PrintWriter out = response.getWriter();
    out.print(jsonP);

    //doDebugging(suggestions, response);
}

From source file:com.jaeksoft.searchlib.web.ServletTransaction.java

public HashSet<String> getClassDetail(HttpServletRequest request) {
    HashSet<String> classDetail = new HashSet<String>();
    String[] values = request.getParameterValues("details");
    if (values != null)
        for (String value : values)
            classDetail.add(value);//ww  w  .j ava  2s. c o  m
    return classDetail;
}

From source file:com.shopzilla.publisher.web.HomeController.java

@PerfTimed
@RequestMapping(value = "filter", method = RequestMethod.GET)
public String filter(HttpServletRequest request, Model uiModel) {

    StringBuilder query = new StringBuilder();
    Enumeration requestEnum = request.getParameterNames();
    while (requestEnum.hasMoreElements()) {
        String key = (String) requestEnum.nextElement();
        for (String str : request.getParameterValues(key)) {
            query.append(key);/*from www.j  ava2 s  . co  m*/
            query.append(":");
            query.append(str);
            query.append(";");
        }

    }
    query.deleteCharAt(query.length() - 1);
    String queryStr = query.toString();

    this.offers.clear();
    this.products.clear();
    List<Category> categoryList = categoryProviderService.fetchCategories();
    for (Category category : categoryList) {
        CatalogResponse response = categorySearchService.attributeSearch(category.getId(), 10, queryStr);

        this.offers.addAll(response.getOffers());
        this.products.addAll(response.getProducts());
    }

    uiModel.addAttribute("offers", this.offers);
    uiModel.addAttribute("products", this.products);
    uiModel.addAttribute("attributes", this.attributes);

    return "index";
}

From source file:org.openmrs.web.controller.person.RelationshipTypeViewFormController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db/*from   w  w  w  .  j ava 2  s.  c om*/
 *
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();
    if (Context.isAuthenticated()) {

        String[] relationshipTypeIds = request.getParameterValues("relationshipTypeIds");
        String[] displayOrders = request.getParameterValues("displayOrders");
        List<String> preferredTypes = new ArrayList<String>();
        String[] preferredTypesArray = request.getParameterValues("preferredTypes");
        if (preferredTypesArray != null) {
            Collections.addAll(preferredTypes, preferredTypesArray);
        }

        PersonService ps = Context.getPersonService();

        for (int i = 0; i < relationshipTypeIds.length; i++) {
            String id = relationshipTypeIds[i];
            String displayOrder = displayOrders[i];
            Boolean preferred = preferredTypes.contains(id);
            RelationshipType type = ps.getRelationshipType(Integer.valueOf(id));
            type.setWeight(Integer.valueOf(displayOrder));
            type.setPreferred(preferred);
            ps.saveRelationshipType(type);
        }

        String success = getMessageSourceAccessor().getMessage("RelationshipType.views.saved");

        view = getSuccessView();
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success);
    }

    return new ModelAndView(new RedirectView(view));
}

From source file:org.openmrs.web.controller.report.ReportObjectListController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db//from  w w w .jav a2 s  .  c om
 * 
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();
    if (Context.isAuthenticated()) {
        String[] reportObjectList = request.getParameterValues("reportObjectId");
        AdministrationService as = Context.getAdministrationService();

        String success = "";
        String error = "";
        int numDeleted = 0;

        MessageSourceAccessor msa = getMessageSourceAccessor();
        String deleted = msa.getMessage("general.deleted");
        String notDeleted = msa.getMessage("general.cannot.delete");
        String textReport = msa.getMessage("reportingcompatibility.ReportObject.reportObject");
        String noneDeleted = msa.getMessage("reportingcompatibility.ReportObject.nonedeleted");
        if (reportObjectList != null) {
            for (String p : reportObjectList) {
                try {
                    as.deleteReportObject(Integer.valueOf(p));
                    if (!success.equals(""))
                        success += "<br/>";
                    success += textReport + " " + p + " " + deleted;
                    numDeleted++;
                } catch (APIException e) {
                    log.warn("Error deleting report object", e);
                    if (!error.equals(""))
                        error += "<br/>";
                    error += textReport + " " + p + " " + notDeleted;
                }
            }

            if (numDeleted > 3)
                success = numDeleted + " " + deleted;
        } else {
            success += noneDeleted;
        }
        view = getSuccessView();
        if (!success.equals(""))
            httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success);
        if (!error.equals(""))
            httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error);
    }

    return new ModelAndView(new RedirectView(view));
}

From source file:ca.nrc.cadc.search.PackageServlet.java

/**
 * Handle a GET request with the given Registry client to perform the lookup.
 *
 * @param request        The HTTP Request.
 * @param response       The HTTP Response.
 * @param registryClient The RegistryClient to do lookups.
 * @throws IOException        Any request access problems.
 *///  w  ww . ja  v  a  2  s. c  o m
void get(final HttpServletRequest request, final HttpServletResponse response,
        final RegistryClient registryClient) throws IOException {

    // TODO: prior to version 2.5.0, this servlet supported multiple IDs.
    // TODO: Consider how this might be supported in future.
    final String[] idValues = request.getParameterValues("ID");
    if (idValues.length > 1) {
        throw new UnsupportedOperationException("Multiple IDs in package lookup.");
    } else {
        final String IDValue = idValues[0];
        if (IDValue.length() > 0) {
            try {
                final PublisherID publisherID = new PublisherID(URI.create(IDValue));

                final URL serviceURL = registryClient.getServiceURL(publisherID.getResourceID(),
                        Standards.PKG_10, AuthMethod.COOKIE);

                final URIBuilder builder = new URIBuilder(serviceURL.toURI());
                builder.addParameter("ID", IDValue);

                response.sendRedirect(builder.build().toURL().toExternalForm());
            } catch (URISyntaxException e) {
                throw new IOException(String.format("Service URL from %s is invalid.", IDValue), e);
            }
        } else {
            throw new UnsupportedOperationException("Invalid ID in package lookup.");
        }
    }
}

From source file:org.openmrs.module.diabetesmanagement.web.controller.InsulinTypeListController.java

/**
 * The onSubmit method receives the form/command object that was modified by the input form and
 * saves it to the database.//  w w  w . j  a va2  s  . co m
 * 
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 * @param request Current servlet request.
 * @param response Current servlet response.
 * @param command Form object with request parameters bound onto it.
 * @param errors Holder without errors.
 * @return The prepared model and view, or null.
 * @throws Exception In case of errors.
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();
    if (Context.isAuthenticated()) {
        String[] insulinTypeIds = request.getParameterValues("insulinTypeId");
        InsulinTypeService its = (InsulinTypeService) Context.getService(InsulinTypeService.class);

        String success = "";
        String error = "";

        MessageSourceAccessor msa = getMessageSourceAccessor();
        String deleted = msa.getMessage("general.deleted");
        String notDeleted = msa.getMessage("general.cannot.delete");

        try {
            for (String p : insulinTypeIds) {
                try {
                    InsulinType t = its.getInsulinType(Integer.valueOf(p));
                    its.purgeInsulinType(t);
                    if (!success.equals(""))
                        success += "<br/>";
                    success += p + " " + deleted;
                } catch (APIException e) {
                    log.warn("Error deleting InsulinType", e);
                    if (!error.equals(""))
                        error += "<br/>";
                    error += p + " " + notDeleted;
                }
            }
        } catch (NullPointerException e) {
            if (!error.equals(""))
                error += "<br/>";
            error += "diabetesmanagement.error.noInsulinTypeSelected";
            showForm(request, response, errors);
        }

        view = getSuccessView();
        if (!success.equals(""))
            httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success);
        if (!error.equals(""))
            httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error);
    }
    return new ModelAndView(new RedirectView(view));
}