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: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   w  w  w  .j a va 2s.  c om
    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;
}

From source file:com.eufar.asmm.server.DownloadFunction.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("DownloadFunction - the function started");
    ServletContext context = getServletConfig().getServletContext();
    request.setCharacterEncoding("UTF-8");
    String dir = context.getRealPath("/tmp");
    ;/*from   w ww. ja va  2s  .  co m*/
    String filename = "";
    File fileDir = new File(dir);
    try {
        System.out.println("DownloadFunction - create the file on server");
        filename = request.getParameterValues("filename")[0];
        String xmltree = request.getParameterValues("xmltree")[0];

        // format xml code to pretty xml code
        Document doc = DocumentHelper.parseText(xmltree);
        StringWriter sw = new StringWriter();
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setIndent(true);
        format.setIndentSize(4);
        XMLWriter xw = new XMLWriter(sw, format);
        xw.write(doc);

        Writer out = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(dir + "/" + filename), "UTF-8"));
        out.append(sw.toString());
        out.flush();
        out.close();
    } catch (Exception ex) {
        System.out.println("ERROR during rendering: " + ex);
    }
    try {
        System.out.println("DownloadFunction - send file to user");
        ServletOutputStream out = response.getOutputStream();
        File file = new File(dir + "/" + filename);
        String mimetype = context.getMimeType(filename);
        response.setContentType((mimetype != null) ? mimetype : "application/octet-stream");
        response.setContentLength((int) file.length());
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        response.setHeader("Pragma", "private");
        response.setHeader("Cache-Control", "private, must-revalidate");
        DataInputStream in = new DataInputStream(new FileInputStream(file));
        int length;
        while ((in != null) && ((length = in.read(bbuf)) != -1)) {
            out.write(bbuf, 0, length);
        }
        in.close();
        out.flush();
        out.close();
        FileUtils.cleanDirectory(fileDir);
    } catch (Exception ex) {
        System.out.println("ERROR during downloading: " + ex);
    }
    System.out.println("DownloadFunction - file ready to be donwloaded");
}

From source file:org.openmrs.web.controller.user.PrivilegeListController.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  a2s.  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)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    HttpSession httpSession = request.getSession();

    //Locale locale = request.getLocale();
    String view = getFormView();
    if (Context.isAuthenticated()) {
        StringBuilder success = new StringBuilder();
        String error = "";

        MessageSourceAccessor msa = getMessageSourceAccessor();

        String[] privilegeList = request.getParameterValues("privilegeId");
        if (privilegeList != null) {
            UserService us = Context.getUserService();
            String deleted = msa.getMessage("general.deleted");
            String notDeleted = msa.getMessage("Privilege.cannot.delete");
            for (String p : privilegeList) {
                //TODO convenience method deletePrivilege(String) ??
                try {
                    us.purgePrivilege(us.getPrivilege(p));
                    if (!"".equals(success.toString())) {
                        success.append("<br/>");
                    }
                    success.append(p).append(" ").append(deleted);
                } catch (DataIntegrityViolationException e) {
                    error = handlePrivilegeIntegrityException(e, error, notDeleted);
                } catch (APIException e) {
                    error = handlePrivilegeIntegrityException(e, error, notDeleted);
                }
            }
        } else {
            error = msa.getMessage("Privilege.select");
        }

        view = getSuccessView();
        if (!"".equals(success.toString())) {
            httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success.toString());
        }
        if (!"".equals(error)) {
            httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error);
        }
    }

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

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

@Override
public Map<String, Object> referenceData(HttpServletRequest request, StudyCommand command) {
    Study study = command.getStudy();/*from   w  w  w .  java2  s. c om*/

    Map<String, Object> refdata = super.referenceData();
    SolicitedEventTabTable table = null;

    if (request.getParameter(AJAX_REQUEST_ADDEPOCH) != null
            || request.getParameter(AJAX_REQUEST_DELETEEPOCH) != null) {
        String[] termIDs = request.getParameterValues("eachRowTermID");
        table = new SolicitedEventTabTable(study, termIDs, ctcTermDao, lowLevelTermDao);
    } else if (request.getParameter(AJAX_REQUEST_PARAMETER) == null
            && request.getAttribute(AJAX_REQUEST_PARAMETER) == null) {
        table = new SolicitedEventTabTable(study);
    } else {
        // Executes when we try to add one or more rows
        String[] termIDs = (String[]) request.getAttribute("listOfTermIDs");
        String[] terms = (String[]) request.getAttribute("listOfTerms");
        table = new SolicitedEventTabTable(study, termIDs, terms, ctcTermDao);
        refdata.put("numOfnewlyAddedRows", table.getNumOfnewlyAddedRows());
    }

    refdata.put("listOfSolicitedAERows", table.getListOfSolicitedAERows());

    return refdata;
}

From source file:com.krawler.esp.handlers.ProfileHandler.java

public static void deleteUser(Session session, HttpServletRequest request) throws ServiceException {
    try {//from   w ww  .  j av a  2 s  .com
        JSONObject jobj = new JSONObject();
        JSONArray jArr = new JSONArray();

        String[] ids = request.getParameterValues("userids");
        for (int i = 0; i < ids.length; i++) {
            User u = (User) session.load(User.class, ids[i]);
            if (u.getRoleID() == 1) {
                throw new Exception("Cannot delete Administrator");
            }
            //UserLogin userLogin = (UserLogin) session.load(UserLogin.class, ids[i]);
            u.setDeleteflag(1);
            session.saveOrUpdate(u);
            //session.delete(userLogin);
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE(e.getMessage(), e);
    }
}

From source file:com.sr.controller.PamongController.java

@RequestMapping("/tambahpenyakit")
public String penyakit(HttpServletRequest request, ModelMap modelMap) {
    String nim = request.getSession().getAttribute("nim").toString();
    String tanggal = request.getParameter("tanggal_sakit");
    String[] penyakit = request.getParameterValues("namapenyakit");
    for (String sakit : penyakit) {
        pmg.insertPenyakit(sakit, tanggal, nim);
    }//from  ww  w  .  j a v a 2  s .  c o  m
    return "redirect:/pamong/monitoring#tab_kesehatan";
}

From source file:gov.nih.nci.ncicb.cadsr.common.cdebrowser.DataElementSearchBean.java

public DataElementSearchBean(HttpServletRequest request) throws SQLException {
    strArray = request.getParameterValues("SEARCH");
    vdPrefName = StringEscapeUtils.escapeHtml(request.getParameter("txtValueDomain"));
    decPrefName = StringEscapeUtils.escapeHtml(request.getParameter("txtDataElementConcept"));
    csiName = StringEscapeUtils.escapeHtml(request.getParameter("txtClassSchemeItem"));
    searchText = StringEscapeUtils.escapeHtml(request.getParameter("jspKeyword"));
    simpleSearchStr = StringEscapeUtils.escapeHtml(request.getParameter("jspSimpleKeyword"));
    aslName = request.getParameterValues("jspStatus");
    regStatus = request.getParameterValues("regStatus");
    altNames = request.getParameterValues("altName");
    vdIdseq = StringEscapeUtils.escapeHtml(request.getParameter("jspValueDomain"));
    decIdseq = StringEscapeUtils.escapeHtml(request.getParameter("jspDataElementConcept"));
    csCsiIdseq = StringEscapeUtils.escapeHtml(request.getParameter("jspClassification"));
    cdeId = StringEscapeUtils.escapeHtml(request.getParameter("jspCdeId"));
    latVersionInd = StringEscapeUtils.escapeHtml(request.getParameter("jspLatestVersion"));
    contextUse = StringEscapeUtils.escapeHtml(request.getParameter("contextUse"));
    validValue = StringEscapeUtils.escapeHtml(request.getParameter("jspValidValue"));
    altName = StringEscapeUtils.escapeHtml(request.getParameter("jspAltName"));
    basicSearchType = StringEscapeUtils.escapeHtml(request.getParameter("jspBasicSearchType"));
    conceptName = StringEscapeUtils.escapeHtml(request.getParameter("jspConceptName"));
    conceptCode = StringEscapeUtils.escapeHtml(request.getParameter("jspConceptCode"));
    objectClass = StringEscapeUtils.escapeHtml(request.getParameter("jspObjectClass"));
    property = StringEscapeUtils.escapeHtml(request.getParameter("jspProperty"));
    nameSearchMode = StringEscapeUtils.escapeHtml(request.getParameter("jspNameSearchMode"));
    pvSearchMode = StringEscapeUtils.escapeHtml(request.getParameter("jspPVSearchMode"));

    if (contextUse == null) {
        contextUse = "";
    }/*from ww w  . ja v a2 s. c  om*/

    //Prefrences
    //buildContextNameFullList(contextsExcludeList, dbUtil);

    /*
     Moved to diffrent method to support search pref
            
    buildWorkflowFullList(aslNameExcludeList, dbUtil);
    buildRegStatusFullList(regStatusExcludeList,dbUtil);
            
    buildWorkflowList(aslName, dbUtil);
    buildRegStatusList(regStatus,dbUtil);
    buildAlternateNameList(altNames, dbUtil);
    buildContextUseList(contextUse);
    */

    searchInList = new StringBuffer("");

    String[] searchIn = request.getParameterValues("jspSearchIn");
    this.buildSearchInList(searchIn);
}

From source file:org.deegree.test.gui.StressTestController.java

private void doStep2(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Map<String, String> paramsSet = new HashMap<String, String>();
    String[] datasets = request.getParameterValues("datasets");
    if (datasets != null) {
        String datasetsStr = "";
        for (int i = 0; i < datasets.length; i++)
            datasetsStr = datasetsStr + "," + datasets[i];
        paramsSet.put("datasets", datasetsStr);
    }/*from   w  ww . ja va  2s.  c om*/

    String elevModel = request.getParameter("elevModel");
    if (elevModel != null && elevModel.length() > 0)
        paramsSet.put("elevModel", elevModel);

    String pitch = request.getParameter("pitch");
    if (pitch != null && pitch.length() > 0)
        paramsSet.put("pitch", pitch);

    String yaw = request.getParameter("yaw");
    if (yaw != null && yaw.length() > 0)
        paramsSet.put("yaw", yaw);

    String roll = request.getParameter("roll");
    if (roll != null && roll.length() > 0)
        paramsSet.put("roll", roll);

    String distance = request.getParameter("distance");
    if (distance != null && distance.length() > 0)
        paramsSet.put("distance", distance);

    String aov = request.getParameter("aov");
    if (aov != null && aov.length() > 0)
        paramsSet.put("aov", aov);

    String clipping = request.getParameter("clipping");
    if (clipping != null && clipping.length() > 0)
        paramsSet.put("clipping", clipping);

    String crs = request.getParameter("crs");
    if (crs != null && crs.length() > 0)
        paramsSet.put("crs", crs);

    String width = request.getParameter("width");
    if (width != null && width.length() > 0)
        paramsSet.put("width", width);

    String height = request.getParameter("height");
    if (height != null && height.length() > 0)
        paramsSet.put("height", height);

    String scale = request.getParameter("scale");
    if (scale != null && scale.length() > 0)
        paramsSet.put("scale", scale);

    request.getSession().setAttribute("paramsSet", paramsSet);

    RequestDispatcher dispatcher = request.getRequestDispatcher("/wpvs_threads.jsp");
    dispatcher.forward(request, response);
}

From source file:com.bitranger.parknshop.seller.controller.SellerPublishProductCtrl.java

@RequestMapping(value = "/seller/publishPro", method = RequestMethod.POST)
public void savePro(HttpServletRequest request, HttpServletResponse response) throws IOException {
    //      http://c1-parknshop.qiniudn.com/ceg_huafengv700_1.jpg
    String prefixUrlPic = "http://c1-parknshop.qiniudn.com/";

    PsSeller psSeller = (PsSeller) request.getSession().getAttribute("currentSeller");

    String name = request.getParameter("name");
    String categoryId = request.getParameter("categoryId");
    String[] tagsId = request.getParameterValues("tags[]");
    String[] urlPics = new String[5];
    String[] pics = request.getParameterValues("pics[]");
    String price = request.getParameter("price");

    String firstStr = "";
    // to generate the url pic
    for (int i = 0; i < pics.length; i++) {
        String str = pics[i];// w w  w .  ja v  a  2s .c om
        //String[] splitStr = str.split("\\\\");
        pics[i] = prefixUrlPic + str;

        if (i == 0) {
            firstStr = pics[i];
        }
    }

    for (int i = 0; i < pics.length; i++) {
        urlPics[i] = pics[i];
    }
    //String promotion = request.getParameter("promotion");
    String description = request.getParameter("description");
    String extra1 = request.getParameter("extra1");

    PsShop psShop = psShopDAO.findBySellerId(psSeller.getId()).get(0);

    PsItem psItem = new PsItem();
    psItem.setPsShop(psShop);

    PsCategory psCategory = categoryDAO.findById(Integer.parseInt(categoryId));
    psItem.setPsCategory(psCategory);

    psItem.setName(name);
    psItem.setIntroduction(description);
    psItem.setPrice(Double.parseDouble(price));
    psItem.setExtra1(extra1);

    Set<PsTag> tags = new HashSet<PsTag>();

    if (tagsId != null) {
        List<PsTag> tagsList = tagDAO.findTagByIds(tagsId);
        for (int i = 0; i < tagsList.size(); i++) {
            tags.add(tagsList.get(i));
        }
    }

    String urlPicrures = "";

    System.out.println("urlPics length : " + pics.length);

    if (urlPics != null) {

        if (pics.length < 5) {

            for (int j = pics.length; j < 5; j++) {
                urlPics[j] = firstStr;
            }
        }

        for (int i = 0; i < 5; i++) {

            urlPicrures += urlPics[i];
            if (i != urlPics.length - 1) {
                urlPicrures += ";";
            }
        }

    }

    psItem.setUrlPicture(urlPicrures);
    psItem.setPsTags(tags);
    psItem.setCountPurchase(0);
    psItem.setCountClick(0);
    psItem.setCountFavourite(0);
    psItem.setVote(new Double(0));
    psItem.setTimeCreated(new Timestamp(System.currentTimeMillis()));

    psItemDAO.save(psItem);

    //System.out.println(name + "-" + categoryId);
    PrintWriter out = response.getWriter();
    out.write("success");
    out.flush();
    out.close();

}

From source file:org.openmrs.module.drugorderexport.web.controller.StartTreatmentController.java

/**
 * @see org.springframework.web.servlet.mvc.AbstractFormController#handleRequestInternal(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *///from  w  w w  .jav a2 s.  co  m
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // TODO Auto-generated method stub
    Map<String, Object> map = new HashMap<String, Object>();
    List<Patient> patientsExport = new ArrayList<Patient>();
    List<Object[]> objectsList = new ArrayList<Object[]>();

    String checkedValueStr[] = null;
    int checkedValue = 0;
    if (request.getParameterValues("checkValue") != null) {
        checkedValueStr = request.getParameterValues("checkValue");

        checkedValue = Integer.parseInt(checkedValueStr[0]);
    }
    if (request.getMethod().equalsIgnoreCase("post")) {

        List<Integer> patientIds = new ArrayList<Integer>();

        Date startDate = null;
        Date endDate = null;

        DrugOrderService service = Context.getService(DrugOrderService.class);

        String startD = request.getParameter("startdate");
        String endD = request.getParameter("enddate");

        String gender = request.getParameter("gender"), minAge = request.getParameter("minAge"),
                maxAge = request.getParameter("maxAge"), minBirthdate = request.getParameter("minBirthdate"),
                maxBirthdate = request.getParameter("maxBirthdate");

        SimpleDateFormat df = OpenmrsUtil.getDateFormat();

        Date mnBirthdate = null;
        Date mxBirthdate = null;
        Date mnAge = null;
        Date mxAge = null;

        if (startD != null && startD.length() != 0) {
            startDate = df.parse(startD);
        }
        if (endD != null && endD.length() != 0) {
            endDate = df.parse(endD);
        }
        if (minBirthdate != null && minBirthdate.length() != 0) {
            mnBirthdate = df.parse(minBirthdate);
        }
        if (maxBirthdate != null && maxBirthdate.length() != 0) {
            mxBirthdate = df.parse(maxBirthdate);
        }

        if (maxAge != null && maxAge.length() != 0) {
            mxAge = service.getDateObjectFormAge(Integer.parseInt(maxAge));
        }
        if (minAge != null && minAge.length() != 0) {
            mnAge = service.getDateObjectFormAge(Integer.parseInt(minAge));

        }
        String arvDrugConceptIds = DrugOrderExportUtil.gpGetARVConceptIds();

        patientIds = service.getPatientWhoStartedOnDate(startDate, endDate, gender, mnAge, mxAge, mnBirthdate,
                mxBirthdate);

        List<Integer> list = new ArrayList<Integer>();

        if (checkedValue == 1) {
            if (endDate == null)
                endDate = new Date();
            patientIds = service.getActiveOnDrugsPatients(patientIds, arvDrugConceptIds, endDate);
        }

        for (Integer patientId : patientIds) {
            Patient patient = new Patient();

            patient = Context.getPatientService().getPatient(patientId);
            if (!patient.getVoided())
                patientsExport.add(patient);

            Date startTreatmentDate = null;
            Date lastEncounterDate = null;
            Date lastVisitDate = null;
            String startTreatmentDateStr = "";
            String lastEncounterDateStr = "";
            String lastVisitDateStr = "";

            if (service.getPatientLastVisitDate(patientId) != null) {
                lastVisitDate = service.getPatientLastVisitDate(patientId);
                lastVisitDateStr = lastVisitDate.toString();
            }
            if (service.getWhenPatStartedXRegimen(patientId, DrugOrderExportUtil.gpGetARVDrugsIds()) != null) {
                startTreatmentDate = service.getWhenPatientStarted(patient);
                startTreatmentDateStr = startTreatmentDate.toString();
            }
            if (service.getPatientLastEncounterDate(patientId) != null) {
                lastEncounterDate = service.getPatientLastEncounterDate(patientId);
                lastEncounterDateStr = lastEncounterDate.toString();
            }

            objectsList.add(new Object[] { Context.getPersonService().getPerson(patientId),
                    startTreatmentDateStr, lastEncounterDateStr, lastVisitDateStr });
        }

        // for data exportation
        if (request.getParameter("export") != null && !request.getParameter("export").equals("")) {

            if (Context.getAuthenticatedUser().hasPrivilege("Export Collective Patient Data")) {
                if (request.getParameter("export").equals("excel"))
                    DrugOrderExportUtil.exportData(request, response, patientsExport);
                if (request.getParameter("export").equals("pdf"))
                    DrugOrderExportUtil.exportToPDF(request, response, patientsExport);
            } else
                map.put("msg", "Required Privilege : [Export Collective Patient Data]");

        }

        map.put("objectsList", objectsList);
        map.put("collectionSize", patientsExport.size());
        map.put("checkedValueExport", checkedValue);

        Date now = new Date();

        if (startDate != null)
            map.put("startdate", df.format(startDate));

        if (endDate != null)
            map.put("enddate", df.format(endDate));

        if (gender.equals("f"))
            map.put("gender", "Female");
        else if (gender.equals(""))
            map.put("gender", "Any");
        else
            map.put("gender", "Male");
        if (mnAge != null)
            map.put("minAge", now.getYear() - mnAge.getYear());
        if (mxAge != null)
            map.put("maxAge", now.getYear() - mxAge.getYear());
        if (mnBirthdate != null)
            map.put("minBirthdate", df.format(mnBirthdate));
        if (mxBirthdate != null)
            map.put("maxBirthdate", df.format(mxBirthdate));

    }
    return new ModelAndView(getViewName(), map);
}