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:cn.itcast.bbs.controller.BbsServlet.java

private void register(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    User user = new User();
    Enumeration<String> enums = request.getParameterNames();
    try {/*from  w w  w . j ava  2s.c  o  m*/
        while (enums.hasMoreElements()) {
            String name = enums.nextElement();
            if (name.equals("method") || name.equals("checkCode")) {
                continue;
            }
            String[] value = request.getParameterValues(name);
            //System.out.println(name+":"+value[0]);
            BeanUtils.setProperty(user, name, value);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    String checkCode = request.getParameter("checkCode");
    HttpSession session = request.getSession();
    String ideacheckCode = (String) session.getAttribute("checkCode");
    try {
        //???
        if (checkCode.equals(ideacheckCode)) {
            RegisterForm registerForm = new RegisterForm();
            //??????
            if (registerForm.validate(user)) {
                if (service.findUser(user.getUsername()) == null) {
                    if (registerForm.validate2Password(user)) {
                        session.setAttribute("user", user);
                        List<String> usernameList = (List<String>) this.getServletContext()
                                .getAttribute("usernameList");
                        usernameList.add(user.getUsername());
                        service.saveUser(user);
                        request.setAttribute("message", "<font color='red'>??</font>");
                        response.setHeader("Refresh", "2;/my-bbs/");
                        request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
                    } else {
                        //??
                        request.setAttribute("passmessage",
                                "<font color='red'>???</font>");
                        request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
                    }
                } else {
                    //??
                    request.setAttribute("usermessage", "<font color='red'>??</font>");
                    request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
                }
            } else {
                //?????
                request.setAttribute("registerForm", registerForm);
                request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
            }
        } else {
            //???
            request.setAttribute("checkmessage",
                    "<font color='red'>????</font>");
            request.getRequestDispatcher("/WEB-INF/bbs/register.jsp").forward(request, response);
        }
        request.setAttribute("user", user);
    } catch (Exception e) {
        e.printStackTrace();
        request.setAttribute("message", "");
        request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response);
    }
}

From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.PurchaseJspBean.java

/**
 * Returns the confirmation message to delete purchases
 *
 * @param request The Http request//  w  ww  . j av a  2  s.  c om
 * @return the html code message
 */
public String getMasseDeletePurchase(HttpServletRequest request) {
    String[] parameterValues = request.getParameterValues(PARAMETER_PURCHASES_ID);

    // if no case checked
    if (parameterValues == null) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_DELETE_MASSE_PURCHASE_NO_CHECK,
                AdminMessage.TYPE_STOP);
    }

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

    try {
        for (String id : parameterValues) {
            urlParam.put(MARK_PURCHASSE_ID + Integer.parseInt(id), Integer.parseInt(id));
        }
    } catch (NumberFormatException e) {
        LOGGER.debug(e);

        return AdminMessageService.getMessageUrl(request, StockConstants.MESSAGE_ERROR_OCCUR,
                AdminMessage.TYPE_STOP);
    }

    boolean masse = urlParam.size() > 1;

    String strJspBack = JSP_MANAGE_OFFERS;

    return AdminMessageService.getMessageUrl(request,
            masse ? MESSAGE_CONFIRMATION_MASSE_DELETE_PURCHASE : MESSAGE_CONFIRMATION_DELETE_PURCHASE, null,
            MESSAGE_TITLE_CONFIRMATION_DELETE_PURCHASE, JSP_DO_DELETE_PURCHASE,
            BilletterieConstants.TARGET_SELF, AdminMessage.TYPE_CONFIRMATION, urlParam, strJspBack);
}

From source file:edu.stanford.muse.webapp.JSPHelper.java

public static Set<Blob> selectAttachments(HttpServletRequest request, HttpSession session,
        boolean only_apply_to_filtered_docs, boolean or_not_and) throws UnsupportedEncodingException {
    // below are all the controls for selecting docs 
    String term = request.getParameter("term"); // search term
    String[] attachments = request.getParameterValues("attachment");
    Archive archive = JSPHelper.getArchive(session);
    Collection<Document> allDocs = getAllDocsAsSet(session, only_apply_to_filtered_docs);
    if (Util.nullOrEmpty(allDocs))
        return new LinkedHashSet<Blob>();

    BlobStore attachmentsStore = archive.blobStore;

    Indexer indexer;/*from   www.ja v  a2 s  . com*/
    indexer = archive.indexer;

    // the raw request param val is in 8859 encoding, interpret the bytes as utf instead

    /**
     * there is a little overlap between datasetId and docForDocIds.
     * probably datasetIds can be got rid of?
     */
    Set<Blob> blobsForTerm = null, blobsForAttachments = null;

    if (!Util.nullOrEmpty(term)) {
        term = JSPHelper.convertRequestParamToUTF8(term);
        if (isRegexSearch(request)) {
            // TODO: not implemented yet
            //assert(false);
            return null;
        } else {
            blobsForTerm = archive.blobsForQuery(term);
        }
    }

    if (!Util.nullOrEmpty(attachments)) {
        attachments = JSPHelper.convertRequestParamsToUTF8(attachments);
        blobsForAttachments = IndexUtils.getBlobsForAttachments((Collection) allDocs, attachments,
                attachmentsStore);
    }

    if (blobsForTerm == null)
        return blobsForAttachments;
    if (blobsForAttachments == null)
        return blobsForTerm;

    if (or_not_and) {
        return Util.setUnion(blobsForTerm, blobsForAttachments);
    } else {
        return Util.setIntersection(blobsForTerm, blobsForAttachments);
    }
}

From source file:org.openmrs.web.controller.patient.MergePatientsFormController.java

/**
 * Called prior to form display. Allows for data to be put in the request to be used in the view
 *
 * @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest)
 *///from  w w  w  .  j  a v  a 2s .  c o m
@Override
protected Map<String, Object> referenceData(HttpServletRequest request, Object obj, Errors errors)
        throws Exception {

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

    Patient p1 = (Patient) obj;
    Patient p2 = new Patient();
    Collection<Encounter> patient1Encounters = new Vector<Encounter>();
    Collection<Encounter> patient2Encounters = new Vector<Encounter>();
    List<Patient> patientList = new ArrayList<Patient>();
    List<Collection<Encounter>> encounterList = new ArrayList<Collection<Encounter>>();
    if (Context.isAuthenticated()) {
        EncounterService es = Context.getEncounterService();
        patient1Encounters = es.getEncountersByPatient(p1);

        String[] patientIds = request.getParameterValues("patientId");
        if (patientIds != null) {
            for (String patient : patientIds) {
                patientList.add(Context.getPatientService().getPatient(Integer.valueOf(patient)));
                encounterList.add(es.getEncountersByPatient(
                        Context.getPatientService().getPatient(Integer.valueOf(patient))));
            }
        }
        if (patientIds != null && patientIds.length > 1 && !patientIds[0].equals(patientIds[1])) {
            String patientId = patientIds[1];
            Integer pId = Integer.valueOf(patientId);
            p2 = Context.getPatientService().getPatient(pId);
            patient2Encounters = es.getEncountersByPatient(p2);
        }

    }

    map.put("patient1Encounters", patient1Encounters);
    map.put("patient2Encounters", patient2Encounters);
    map.put("patientEncounters", encounterList);
    map.put("patient2", p2);
    map.put("patientList", patientList);
    map.put("modalMode", request.getParameter("modalMode"));
    List<Integer> patientIdsWithUnvoidedOrders = new ArrayList<Integer>();
    OrderService os = Context.getOrderService();
    for (Patient pat : patientList) {
        List<Order> orders = os.getAllOrdersByPatient(pat);
        for (Order o : orders) {
            if (!o.isVoided()) {
                patientIdsWithUnvoidedOrders.add(pat.getId());
                break;
            }
        }
    }
    map.put("patientIdsWithUnvoidedOrders", patientIdsWithUnvoidedOrders);

    return map;
}

From source file:com.jaspersoft.jasperserver.rest.utils.Utils.java

/**
 * Look for parameters provided by the client.
 *
 * @param req  HttpServletRequest/*from w  w  w .  j a  v a2  s .c o  m*/
 * @return Map&lt;String,Object&gt;
 */
public Map<String, Object> extractParameters(HttpServletRequest req) {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Enumeration penum = req.getParameterNames();
    while (penum.hasMoreElements()) {
        String pname = (String) penum.nextElement();
        if (pname.startsWith("P_")) {
            parameters.put(pname.substring(2), req.getParameter(pname));
        } else if (pname.startsWith("PL_")) {
            parameters.put(pname.substring(3), Arrays.asList(req.getParameterValues(pname)));
        }
    }
    return parameters;
}

From source file:fr.paris.lutece.portal.web.workgroup.AdminWorkgroupJspBean.java

/**
 * Process the data capture form for assign users to a workgroup
 *
 * @param request The HTTP Request//from   ww  w  . j a v  a  2s .  c om
 * @return The Jsp URL of the process result
 */
public String doAssignUsers(HttpServletRequest request) {
    String strReturn;

    String strActionCancel = request.getParameter(PARAMETER_CANCEL);

    if (strActionCancel != null) {
        strReturn = JSP_MANAGE_WORKGROUPS;
    } else {
        String strWorkgroupKey = request.getParameter(PARAMETER_WORKGROUP_KEY);

        //retrieve the selected portlets ids
        String[] arrayUsersIds = request.getParameterValues(PARAMETER_USERS_LIST);

        if ((arrayUsersIds != null)) {
            for (int i = 0; i < arrayUsersIds.length; i++) {
                int nUserId = Integer.parseInt(arrayUsersIds[i]);
                AdminUser user = AdminUserHome.findByPrimaryKey(nUserId);

                if (!AdminWorkgroupHome.isUserInWorkgroup(user, strWorkgroupKey)) {
                    AdminWorkgroupHome.addUserForWorkgroup(user, strWorkgroupKey);
                }
            }
        }

        strReturn = JSP_ASSIGN_USERS_TO_WORKGROUPS + "?" + PARAMETER_WORKGROUP_KEY + "=" + strWorkgroupKey;
    }

    return strReturn;
}

From source file:com.virtusa.akura.student.controller.StudentClassController.java

/**
 * handle POST requests for StudentClass view with data.
 * /*ww w . j a va2 s . c  om*/
 * @param request - HttpServletRequest
 * @return the name of the view.
 * @throws AkuraException throws when exception occurs.
 */
@RequestMapping(value = ACTION_FOR_SAVE_STUDENT_LIST, method = RequestMethod.POST)
public ModelAndView saveStudentList(HttpServletRequest request) throws AkuraException {

    String[] toList = request.getParameterValues(REQUEST_TO_LIST);
    String grade = request.getParameter(PARAM_NAME_SELECTED_GRADE);
    String year = request.getParameter(PARAM_NAME_SELECTED_YEAR);
    String newYear = request.getParameter(REQUEST_NEW_SELECTED_YEAR);
    String newClassGrade = request.getParameter(REQUEST_NEW_SELECTED_GRADE);

    int selectedNewYear = 0;
    int clsGradeId = 0;
    if (newClassGrade != null && !"".equals(newClassGrade)) {
        clsGradeId = Integer.parseInt(newClassGrade);
    }
    if (newYear != null && !"".equals(newYear)) {
        selectedNewYear = generateSelectedYear(newYear);
    }
    request.getParameterMap();
    ModelMap modelMap = new ModelMap();

    // starts validations - all mandatory parameters should be not null
    if ((!"".equals(newYear)) && (!"".equals(newClassGrade)) && (toList != null) && (!"".equals(grade))
            && (!"".equals(year))) {
        boolean fail = false;
        StringBuilder failStudents = new StringBuilder();
        String newYearConverted = newYear + UNDER_SCOPE + UNDER_SCOPE;
        Date dateSelectedYear = DateUtil.getDateTypeYearValue(newYearConverted); // selected year
        int intNewYear = DateUtil.getYearFromDate(dateSelectedYear);

        ClassGrade classGradeNew = commonService.findClassGrade(clsGradeId);
        List<StudentClassInfo> studentClassNewList = new ArrayList<StudentClassInfo>();

        // handling student in the list which not belongs to any class
        if (NEW_STUDENTS.equals(grade)) {
            for (String z : toList) { // iterating student id from the input list
                int studId = Integer.parseInt(z);

                // assigns the new students that the first date of school is less than or equal
                // to the new selected date.
                assignNewStudents(dateSelectedYear, classGradeNew, studentClassNewList, intNewYear, studId);
            }
        } else {
            for (String z : toList) { // iterating student id from the input list

                int studId = Integer.parseInt(z);
                List<StudentClassInfo> studentClassInfos = studentService.getStudentClassInfoByStudentId(studId,
                        intNewYear);

                // as year, student id and class grade id is unique in db, only one or no record is coming
                if (studentClassInfos == null || studentClassInfos.isEmpty()) {

                    // there is no item for new year selected. hence creating new one and add to list.
                    StudentClassInfo sciObjNew = createNewClassInfo(dateSelectedYear, classGradeNew, studId);
                    studentClassNewList.add(sciObjNew);
                } else {
                    // taking the 1st item as there will be only one item
                    StudentClassInfo item = studentClassInfos.get(0);

                    // if it is same grade, no issues, no marks have been entered for the student for
                    // different grade. lazy false
                    if (item.getClassGrade().getGrade().getGradeId() == classGradeNew.getGrade().getGradeId()
                            || item.getStudentTermMarks() == null || item.getStudentTermMarks().isEmpty()) {
                        item.setClassGrade(classGradeNew);
                        studentClassNewList.add(item);
                    } else {
                        if (failStudents.length() == 0) {
                            failStudents.append(item.getStudent().getFullName());
                        } else {
                            failStudents.append(",");
                            failStudents.append(item.getStudent().getFullName());
                        }
                        fail = true;
                    }
                }
            }
        }
        if (!fail) {
            // checks the marking completion status.
            List<Boolean> markingStatus = studentService.isExistMarkingCompleted(clsGradeId, newYear);

            boolean status = checkMarkCompletionStatus(grade, newYear, clsGradeId, markingStatus);
            if (status) {

                // assigns into a class.
                assignToClass(request, clsGradeId, modelMap, intNewYear, studentClassNewList);
            } else {
                getErrorMessage(modelMap, STUDENT_MARK_COMPLETION, clsGradeId, request, intNewYear);
            }
        } else {
            String message = new ErrorMsgLoader().getErrorMessage(STUDENT_SUBJECTS_ASSIGNED);
            modelMap.addAttribute(MESSAGE, message + failStudents.toString());
            populatedSelectedValues(modelMap, clsGradeId, request, intNewYear);
        }
    } else {
        getErrorMessage(modelMap, MANDATORY_FIELD_ERROR_CODE, clsGradeId, request, selectedNewYear);
    }
    if (!modelMap.containsValue(new ErrorMsgLoader().getErrorMessage(STUDENT_SUCCESSFULLY_ASSIGNED))) {
        Map<String, Object> finalMap = new TreeMap<String, Object>();
        loadClassInfoPage(grade, year, modelMap, finalMap);
    }
    return new ModelAndView(VIEW_STUDENT_CLASS_PAGE, modelMap);
}

From source file:com.boxfuse.samples.tomee.ActionServlet.java

private void process(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String action = request.getParameter("action");

    if ("Add".equals(action)) {

        String title = request.getParameter("title");
        String director = request.getParameter("director");
        String genre = request.getParameter("genre");
        int rating = Integer.parseInt(request.getParameter("rating"));
        int year = Integer.parseInt(request.getParameter("year"));

        Movie movie = new Movie(title, director, genre, rating, year);

        moviesBean.addMovie(movie);// w  ww.  ja  v a  2  s . co  m
        response.sendRedirect("moviefun");
        return;

    } else if ("Remove".equals(action)) {

        String[] ids = request.getParameterValues("id");
        for (String id : ids) {
            moviesBean.deleteMovieId(new Long(id));
        }

        response.sendRedirect("moviefun");
        return;

    } else {
        String key = request.getParameter("key");
        String field = request.getParameter("field");

        int count = 0;

        if (StringUtils.isEmpty(key) || StringUtils.isEmpty(field)) {
            count = moviesBean.countAll();
            key = "";
            field = "";
        } else {
            count = moviesBean.count(field, key);
        }

        int page = 1;

        try {
            page = Integer.parseInt(request.getParameter("page"));
        } catch (Exception e) {
        }

        int pageCount = (count / PAGE_SIZE);
        if (pageCount == 0 || count % PAGE_SIZE != 0) {
            pageCount++;
        }

        if (page < 1) {
            page = 1;
        }

        if (page > pageCount) {
            page = pageCount;
        }

        int start = (page - 1) * PAGE_SIZE;
        List<Movie> range;

        if (StringUtils.isEmpty(key) || StringUtils.isEmpty(field)) {
            range = moviesBean.findAll(start, PAGE_SIZE);
        } else {
            range = moviesBean.findRange(field, key, start, PAGE_SIZE);
        }

        int end = start + range.size();

        request.setAttribute("count", count);
        request.setAttribute("start", start + 1);
        request.setAttribute("end", end);
        request.setAttribute("page", page);
        request.setAttribute("pageCount", pageCount);
        request.setAttribute("movies", range);
        request.setAttribute("key", key);
        request.setAttribute("field", field);
    }

    request.getRequestDispatcher("WEB-INF/moviefun.jsp").forward(request, response);
}

From source file:com.virtusa.akura.student.controller.StudentAssignmentMarkController.java

/**
 * Save student assignment marks.//from  ww  w.ja  va2  s  . c  o  m
 * 
 * @param modelMap the model map
 * @param request the request
 * @return the model and view
 * @throws AkuraAppException the akura app exception
 */
@RequestMapping(value = SAVE_STUDENT_ASSIGNMENT_MARKS_HTM)
public ModelAndView saveStudentAssignmentMarks(ModelMap modelMap, HttpServletRequest request)
        throws AkuraAppException {

    String assignmentId = request.getParameter(ASSIGNMENT_ID);
    String classGradeId = request.getParameter(CLASS_GRADE_ID);
    String[] studentAssignmentMarksArray = request.getParameterValues(ASSIGNMENT_MARK_VALUE);
    int intAssignmentId = Integer.parseInt(assignmentId);

    Assignment assignment = commonService.findAssignmentById(intAssignmentId);

    boolean enteredMarks = false;
    for (String assignmentMark : studentAssignmentMarksArray) {
        if (StringUtils.isNotEmpty(assignmentMark)) {
            enteredMarks = true;
            break;
        }
    }

    List<StudentAssignmentMark> studentAssignmentMarksList = new ArrayList<StudentAssignmentMark>();

    if (enteredMarks) {

        int gradeSubjectId = 0;
        if (assignment != null) {
            gradeSubjectId = assignment.getGradeSubject().getGradeSubjectId();
        }

        int intClassGradeId = 0;
        if (classGradeId != null) {
            intClassGradeId = Integer.parseInt(classGradeId);
        }

        List<ClassWiseStudentsSubjectsDTO> classWiseStudentsSubjectsDTOs = studentService
                .getClassWiseStudentListBySubject(intClassGradeId, gradeSubjectId, DateUtil.currentYear());

        addAssignmentMark(modelMap, assignmentId, studentAssignmentMarksArray, assignment,
                classWiseStudentsSubjectsDTOs, studentAssignmentMarksList);

    } else {
        String message = AkuraWebConstant.EMPTY_STRING;
        if (assignment.getIsMarks()) {
            message = new ErrorMsgLoader().getErrorMessage(STUDENT_ASSIGNMENT_MARKS_EMPTY);
        } else {
            message = new ErrorMsgLoader().getErrorMessage(REF_UI_STUDENT_MARKASSIGN_INVALIDGRADING);
        }
        modelMap.addAttribute(MESSAGE, message);
    }
    searchStudentAssignmentMarks(modelMap, request);
    return new ModelAndView(STUDENT_STUDENT_ASSIGNMENT_MARKS);
}