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:ShoppingCartViewerHidden.java

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

    out.println("<HEAD><TITLE>Current Shopping Cart Items</TITLE></HEAD>");
    out.println("<BODY>");

    // Cart items are passed in as the item parameter.
    String[] items = req.getParameterValues("item");

    // Print the current cart items.
    out.println("You currently have the following items in your cart:<BR>");
    if (items == null) {
        out.println("<B>None</B>");
    } else {/*  w w w.j a v  a 2s .c o  m*/
        out.println("<UL>");
        for (int i = 0; i < items.length; i++) {
            out.println("<LI>" + items[i]);
        }
        out.println("</UL>");
    }

    // Ask if the user wants to add more items or check out.
    // Include the current items as hidden fields so they'll be passed on.
    out.println("<FORM ACTION=\"/servlet/ShoppingCart\" METHOD=POST>");
    if (items != null) {
        for (int i = 0; i < items.length; i++) {
            out.println("<INPUT TYPE=HIDDEN NAME=\"item\" VALUE=\"" + items[i] + "\">");
        }
    }
    out.println("Would you like to<BR>");
    out.println("<INPUT TYPE=SUBMIT VALUE=\" Add More Items \">");
    out.println("<INPUT TYPE=SUBMIT VALUE=\" Check Out \">");
    out.println("</FORM>");

    out.println("</BODY></HTML>");
}

From source file:org.esgf.globusonline.GOauthView4Controller.java

@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public ModelAndView doPost(final HttpServletRequest request) {

    //grab the dataset name, file names and urls from the query string
    String dataset_name = request.getParameter("id");
    String[] file_names = request.getParameterValues("child_id");
    String[] file_urls = request.getParameterValues("child_url");

    Map<String, Object> model = new HashMap<String, Object>();

    String myproxyServerStr = null;

    HttpSession session = request.getSession(false);
    if (session == null) {
    } else {//  ww  w. ja va 2 s  .  co m
    }

    try {
        //get the openid here from the cookie
        Cookie[] cookies = request.getCookies();
        String openId = "";
        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals("esgf.idp.cookie")) {
                openId = cookies[i].getValue();
            }
        }

        LOG.debug("Got User OpenID: " + openId);
        myproxyServerStr = Utils.resolveMyProxyViaOpenID(openId);
        LOG.debug("Using MyProxy Server: " + myproxyServerStr);

        ESGFProperties esgfProperties = new ESGFProperties();
        UserInfoDAO uid = new UserInfoDAO(esgfProperties);
        UserInfo userInfo = uid.getUserByOpenid(openId);
        String myproxyUserName = userInfo.getUserName();

        LOG.debug("Got MyProxy Username: " + myproxyUserName);
        //System.out.println("Got MyProxy Username: " + myproxyUserName);

        if (request.getParameter(GOFORMVIEW_MODEL) != null) {
            //it should never come here...
        } else {
            session.setAttribute("myproxyServerStr", myproxyServerStr);
            session.setAttribute("myproxyUserName", myproxyUserName);
            //place the dataset name, file names and urls into the model
            model.put(GOFORMVIEW_MYPROXY_SERVER, myproxyServerStr);
            model.put(GOFORMVIEW_SRC_MYPROXY_USER, myproxyUserName);
            //   model.put(GOFORMVIEW_FILE_URLS, file_urls);
            //   model.put(GOFORMVIEW_FILE_NAMES, file_names);
            model.put(GOFORMVIEW_DATASET_NAME, dataset_name);
        }
    } catch (YadisException ye) {
        String eMsg = ye.toString();
        if (eMsg.indexOf("0x702") != -1) {
            model.put(GOFORMVIEW_ERROR, "error");
            model.put(GOFORMVIEW_ERROR_MSG,
                    "Please <a href=\"login\">Login</a>" + " before trying to download data!");
        } else {
            String errorMsg = "Failed to resolve OpenID: " + ye;
            LOG.error("Failed to resolve OpenID: " + ye);
            model.put(GOFORMVIEW_ERROR, "error");
            model.put(GOFORMVIEW_ERROR_MSG, errorMsg + "<br><br>Please make sure that you're"
                    + " logged in as a valid user before trying to download data!<br><br>");
        }
    } catch (Exception e) {
        String errorMsg = "Failed to resolve OpenID: " + e;
        LOG.error("Failed to resolve OpenID: " + e);
        model.put(GOFORMVIEW_ERROR, "error");
        model.put(GOFORMVIEW_ERROR_MSG, errorMsg + "<br><br>Please make sure that you're"
                + " logged in as a valid user before trying to download data!<br><br>");
    }
    return new ModelAndView("goauthview4", model);
}

From source file:org.openmrs.web.controller.program.ProgramListController.java

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();//w  w  w  .  ja  va2  s . c  om
    if (Context.isAuthenticated()) {
        String[] programList = request.getParameterValues("programId");
        ProgramWorkflowService ps = Context.getProgramWorkflowService();

        StringBuilder success = new StringBuilder("");
        StringBuilder error = new StringBuilder();

        MessageSourceAccessor msa = getMessageSourceAccessor();
        String deleted = msa.getMessage("general.deleted");
        String notDeleted = msa.getMessage("general.cannot.delete");
        String textProgram = msa.getMessage("Program.program");
        String noneDeleted = msa.getMessage("Program.nonedeleted");
        if (programList != null) {
            for (String p : programList) {

                try {
                    ps.purgeProgram(ps.getProgram(Integer.valueOf(p)));
                    if (!"".equals(success.toString())) {
                        success.append("<br/>");
                    }
                    success.append(textProgram);
                    success.append(" ");
                    success.append(p);
                    success.append(" ");
                    success.append(deleted);
                } catch (APIException e) {
                    log.warn("Error deleting program", e);
                    if (!"".equals(error.toString())) {
                        error.append("<br/>");
                    }
                    error.append(textProgram).append(" ").append(p).append(" ").append(notDeleted);
                }
            }
        } else {
            success.append(noneDeleted);
        }
        view = getSuccessView();
        if (!"".equals(success.toString())) {
            httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success.toString());
        }
        if (!"".equals(error.toString())) {
            httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error.toString());
        }
    }

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

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

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db//  w  ww  . j a v  a  2 s . c  o  m
 * 
 * @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[] formList = request.getParameterValues("formId");
        FormService fs = Context.getFormService();
        //FormService rs = new TestFormService();

        StringBuilder success = new StringBuilder("");
        StringBuilder error = new StringBuilder("");

        MessageSourceAccessor msa = getMessageSourceAccessor();
        String deleted = msa.getMessage("general.deleted");
        String notDeleted = msa.getMessage("general.cannot.delete");
        String textForm = msa.getMessage("Form.form");
        String noneDeleted = msa.getMessage("Form.nonedeleted");
        if (formList != null) {
            for (String p : formList) {
                //TODO convenience method deleteForm(Integer) ??
                try {
                    fs.purgeForm(fs.getForm(Integer.valueOf(p)));
                    if (!"".equals(success.toString())) {
                        success.append("<br/>");
                    }
                    success.append(textForm).append(" ").append(p).append(" ").append(deleted);
                } catch (APIException e) {
                    log.warn("Error deleting form", e);
                    if (!"".equals(error.toString())) {
                        error.append("<br/>");
                    }
                    error.append(textForm).append(" ").append(p).append(" ").append(notDeleted);
                }
            }
        } else {
            success.append(noneDeleted);
        }
        view = getSuccessView();
        if (!"".equals(success.toString())) {
            httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success.toString());
        }
        if (!"".equals(error.toString())) {
            httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error.toString());
        }
    }

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

From source file:gov.nih.nci.cabig.caaers.web.rule.notification.NotificationsTab.java

@Override
public void onBind(HttpServletRequest request, ReportDefinitionCommand cmd, Errors errors) {
    super.onBind(request, cmd, errors);
    int size = cmd.getEmailNotifications().size();
    for (int i = 0; i < size; i++) {
        String[] roleRecipients = request
                .getParameterValues("emailNotifications[" + i + "].roleBasedRecipients");
        String[] contactRecipients = request
                .getParameterValues("emailNotifications[" + i + "].contactMechanismBasedRecipients");
        PlannedNotification plannedNotification = cmd.getEmailNotifications().get(i);

        List<Recipient> recipients = plannedNotification.getRecipients();
        recipients.clear();//from   www .ja  v a2  s  .com

        if (roleRecipients != null) {
            for (String r : roleRecipients) {
                Recipient roleRecipient = new RoleBasedRecipient(r);
                if (!recipients.contains(roleRecipient))
                    plannedNotification.addRecipient(roleRecipient);
            }
        }

        if (contactRecipients != null) {
            for (String r : contactRecipients) {
                Recipient cRecipient = new ContactMechanismBasedRecipient(r);
                if (!recipients.contains(cRecipient))
                    plannedNotification.addRecipient(cRecipient);
            }
        }

    }
}

From source file:gov.nih.nci.ncicb.cadsr.common.lov.ClassificationsLOVBean.java

private void getClassificationBean(HttpServletRequest request, DBUtil dbUtil, String additionalWhere) {

    try {//from w w w . java 2  s  . c  o  m
        // searchStr = request.getParameter("SEARCH");
        searchStr = request.getParameterValues("SEARCH");
        String csWhere = "";
        String csvWhere = "";
        String csiWhere = "";
        if (searchStr != null) {
            for (int i = 0; i < searchStr.length; i++) {
                if (searchStr[i] == null)
                    searchStr[i] = "";
            }
            if (!searchStr[0].equals("")) {
                String newSearchStr0 = StringReplace.strReplace(searchStr[0], "*", "%");
                // Release 3.0, TT#1178
                newSearchStr0 = StringReplace.strReplace(newSearchStr0, "'", "''");
                csWhere = " and   (upper (cs.long_name) like upper ( '" + newSearchStr0 + "') "
                        + " OR upper (cs.preferred_name) like upper ( '" + newSearchStr0 + "')) ";
            }
            // Release 3.2 GF#1247
            if (!searchStr[1].equals("")) {
                Float newSearchFlt1 = new Float(searchStr[1]);
                csvWhere = " and cs.version = " + newSearchFlt1.toString() + "  ";
            }
            if (!searchStr[2].equals("")) {
                String newSearchStr1 = StringReplace.strReplace(searchStr[2], "*", "%");
                // Release 3.0, TT#1178
                newSearchStr1 = StringReplace.strReplace(newSearchStr1, "'", "''");
                csiWhere = " and upper (csi.long_name) like upper ( '" + newSearchStr1 + "') ";
            }
            if (request.getParameter("chkContext") == null) {
                whereClause = csWhere + csvWhere + csiWhere;
            } else {
                whereClause = csWhere + csvWhere + csiWhere + additionalWhere;
                isContextSpecific = true;
            }

        }
        // pass the following parameters to CommonListCntrlBean
        String[] searchParm = { "cs.long_name", "Classification Scheme", "cs.version", "CS Version", // Release 3.2 GF#1247
                "csi.long_name csi_name", "Class Scheme Item" };
        String[] jspLinkParm = { "csc.cs_csi_idseq", "P_ID" };
        String[] displayParm = { "csi.long_name csi_name", "Class Scheme Item Name",
                "csi.csi_id||'v'||"
                        + "case when csi.version = trunc(csi.version) " + "then to_char(csi.version,'99.9') "
                        + "else to_char(csi.version,'99.99') " + "end csi_version",
                "CSI Public ID Version", "cs.long_name", "CS Long Name",
                "cs.cs_id||'v'||" + "case when cs.version = trunc(cs.version) "
                        + "then  to_char(cs.version,'99.9') " + "else   to_char(cs.version,'99.99') "
                        + "end csversion",
                "CS Public ID Version", // Release 3.2 GF#1247
                "cs_conte.name", "CS Context", "cs.asl_name", "CS Workflow Status", "cs.preferred_definition",
                "CS Definition" };
        String[] sqlStmtParm = new String[2];
        sqlStmtParm[0] = " from sbr.classification_schemes_view cs, sbr.contexts_view cs_conte, "
                + "      sbr.cs_items_view csi, sbr.cs_csi_view csc "
                + " where cs.conte_idseq = cs_conte.conte_idseq "
                //+
                // Release 3.2 GF#1247 " and cs.latest_version_ind = 'Yes' "
                // +
                //" and cs.deleted_ind = 'No' "  //when using view no need for this
                + " and cs.cs_idseq = csc.cs_idseq " + " and csi.csi_idseq = csc.csi_idseq "
                + " and cs.asl_name not in ('RETIRED PHASED OUT','RETIRED DELETED') " + whereClause;
        sqlStmtParm[1] = " order by cs.long_name, csi.long_name ";
        int[] lovPassbackCols = { 0, 4 };

        clb = new CommonLOVBean(request,
                // dBBroker,
                dbUtil, searchParm, jspLinkParm, displayParm, sqlStmtParm, false, lovPassbackCols);

        clb.setCompressFlag(false); // set compress flag
        clb.setLinkCol(0); // set detail page link column, 0-> first;
        // 1->second
        clb.setDetailReq_Type("value_domains"); // set req_type for detail
        // page
        clb.setShowRowNum(40);
        // clb.setPerformQueryToFalse();

        //clb.setJsId(StringEscapeUtils.escapeHtml(request.getParameter("idVar")));
        clb.setJsId("jspClassification");
        //clb.setJsName(StringEscapeUtils.escapeHtml(request.getParameter("nameVar")));
        clb.setJsName("txtClassSchemeItem");
        if (isContextSpecific)
            clb.setExtraURLInfo("&performQuery=false&ckhContext=yes");
        else
            clb.setExtraURLInfo("&performQuery=false");

    } catch (SQLException e) {
        //this.dBBroker = dBBroker;
        log.error("Exception: ", e);
    }
}

From source file:fr.paris.lutece.plugins.workflow.modules.reassignment.service.TaskReassignment.java

/**
 * {@inheritDoc}//from  w  ww  . jav  a 2s .c o  m
 */
@Override
public void processTask(int nIdResourceHistory, HttpServletRequest request, Locale locale) {
    Plugin workflowPlugin = PluginService.getPlugin(WorkflowPlugin.PLUGIN_NAME);
    String[] tabWorkgroups = request.getParameterValues(PARAMETER_WORKGROUPS + "_" + this.getId());
    AdminUser admin = AdminUserService.getAdminUser(request);
    List<String> listWorkgroup = new ArrayList<String>();
    TaskReassignmentConfig config = _taskReassignementConfigService.findByPrimaryKey(this.getId());

    for (int i = 0; i < tabWorkgroups.length; i++) {
        listWorkgroup.add(tabWorkgroups[i]);

        //add history 
        AssignmentHistory history = new AssignmentHistory();
        history.setIdResourceHistory(nIdResourceHistory);
        history.setIdTask(this.getId());
        history.setWorkgroup(tabWorkgroups[i]);
        _assignmentHistoryService.create(history, workflowPlugin);

        if (config.isNotify()) {
            WorkgroupConfig workgroupConfig = _workgroupConfigService.findByPrimaryKey(this.getId(),
                    tabWorkgroups[i], workflowPlugin);

            if ((workgroupConfig != null)
                    && (workgroupConfig.getIdMailingList() != WorkflowUtils.CONSTANT_ID_NULL)) {
                Collection<Recipient> listRecipients = AdminMailingListService
                        .getRecipients(workgroupConfig.getIdMailingList());

                String strSenderEmail = MailService.getNoReplyEmail();

                HashMap<String, Object> model = new HashMap<String, Object>();
                model.put(MARK_MESSAGE, config.getMessage());

                HtmlTemplate t = AppTemplateService.getTemplate(TEMPLATE_TASK_NOTIFICATION_MAIL, locale, model);

                if (config.isUseUserName()) {
                    String strSenderName = I18nService.getLocalizedString(PROPERTY_MAIL_SENDER_NAME, locale);

                    // Send Mail
                    for (Recipient recipient : listRecipients) {
                        // Build the mail message
                        MailService.sendMailHtml(recipient.getEmail(), strSenderName, strSenderEmail,
                                config.getSubject(), t.getHtml());
                    }
                } else {
                    for (Recipient recipient : listRecipients) {
                        // Build the mail message
                        MailService.sendMailHtml(recipient.getEmail(),
                                admin.getFirstName() + " " + admin.getLastName(), admin.getEmail(),
                                config.getSubject(), t.getHtml());
                    }
                }
            }
        }
    }

    //update resource workflow 
    ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey(nIdResourceHistory);
    ResourceWorkflow resourceWorkflow = _resourceWorkflowService.findByPrimaryKey(
            resourceHistory.getIdResource(), resourceHistory.getResourceType(),
            resourceHistory.getWorkflow().getId());
    resourceWorkflow.setWorkgroups(listWorkgroup);
    _resourceWorkflowService.update(resourceWorkflow);
}

From source file:quanlyhocvu.api.web.controller.staff.ManagementNewsController.java

@RequestMapping(value = "save")
public ModelAndView save(HttpServletRequest request) {
    Map<String, Object> model = new HashMap<>();
    //////////////////////
    String title = request.getParameter("title");
    String author = Tools.getCurrentUser();
    Date date = new Date();
    String content = request.getParameter("content");
    String catalogIds[] = request.getParameterValues("catalogs");
    String url = "";
    System.out.println(title + author + content);
    if ("".equals(title) || "".equals(author) || "".equals(content)) {
        model.put("message", "To tin tc khng thnh cng");
        return new ModelAndView("redirect:/guest/home", model);
    }//  w w  w  . j  a  v  a  2s  .c o m

    NewsDTO news = new NewsDTO(title, author, date, content, url, mongoService.getCatalogsFromIds(catalogIds));
    mongoService.insertNews(news);
    model.put("message", "To tin tc thnh cng");
    return new ModelAndView("redirect:/guest/home", model);

}

From source file:org.openmrs.web.controller.program.StateConversionListController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db/*from ww w.  j  av  a2s . com*/
 *
 * @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[] conversionIdList = request.getParameterValues("conceptStateConversionId");
        ProgramWorkflowService pws = Context.getProgramWorkflowService();

        StringBuilder success = new StringBuilder("");
        StringBuilder error = new StringBuilder("");
        int numDeleted = 0;

        MessageSourceAccessor msa = getMessageSourceAccessor();
        String deleted = msa.getMessage("general.deleted");
        String notDeleted = msa.getMessage("general.cannot.delete");
        String textConversion = msa.getMessage("Program.conversion");
        String noneDeleted = msa.getMessage("Program.conversion.nonedeleted");
        if (conversionIdList != null) {
            for (String id : conversionIdList) {
                try {
                    pws.purgeConceptStateConversion(pws.getConceptStateConversion(Integer.valueOf(id)));
                    if (!"".equals(success.toString())) {
                        success.append("<br/>");
                    }
                    success.append(textConversion).append(" ").append(id).append(" ").append(deleted);
                    numDeleted++;
                } catch (APIException e) {
                    log.warn("Error deleting concept state conversion", e);
                    if (!"".equals(error.toString())) {
                        error.append("<br/>");
                    }
                    error.append(textConversion).append(" ").append(id).append(" ").append(notDeleted);
                }
            }

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

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

From source file:jetbrains.buildServer.clouds.azure.arm.web.SettingsController.java

private void doPost(@NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response) {
    final Element xmlResponse = XmlResponseUtil.newXmlResponse();
    final ActionErrors errors = new ActionErrors();
    final String[] resources = request.getParameterValues("resource");
    final List<Promise<Content, Throwable, Void>> promises = new ArrayList<>(resources.length);

    for (final String resource : resources) {
        final ResourceHandler handler = HANDLERS.get(resource);
        if (handler == null)
            continue;

        try {//from w ww  .j  av  a  2s .  c o m
            final Promise<Content, Throwable, Void> promise = handler.handle(request)
                    .fail(new FailCallback<Throwable>() {
                        @Override
                        public void onFail(Throwable result) {
                            LOG.debug(result);
                            errors.addError(resource, result.getMessage());
                        }
                    });
            promises.add(promise);
        } catch (Throwable t) {
            LOG.debug(t);
            errors.addError(resource, t.getMessage());
        }
    }

    if (promises.size() == 0) {
        if (errors.hasErrors()) {
            errors.serialize(xmlResponse);
        }

        writeResponse(xmlResponse, response);
        return;
    }

    final AsyncContext context = request.startAsync(request, response);
    myManager.when(promises.toArray(new Promise[] {})).always(new AlwaysCallback<MultipleResults, OneReject>() {
        @Override
        public void onAlways(Promise.State state, MultipleResults resolved, OneReject rejected) {
            if (errors.hasErrors()) {
                errors.serialize(xmlResponse);
            } else {
                for (OneResult oneResult : resolved) {
                    xmlResponse.addContent((Content) oneResult.getResult());
                }
            }

            writeResponse(xmlResponse, context.getResponse());
            context.complete();
        }
    });
}