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:controler.purchaseServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w  w  w .ja va  2 s.c  o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    DbModules dm = new DbModules();
    HttpSession session = request.getSession(true);

    try {
        String myValues[] = request.getParameterValues("myValues");
        Object attribValue = session.getAttribute("customerID");
        String value = " " + attribValue;
        value = value.trim();
        String message = null;
        if ("null".equals(value) || "".equals(value)) {
            message = "Please log in first to make any purchases";
        } else {
            try {
                message = dm.UpdatePurchase(myValues, value);
            } catch (ParseException ex) {
                Logger.getLogger(purchaseServlet.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        out.print(message);

    } finally {
        out.close();
    }
}

From source file:fr.paris.lutece.plugins.workflow.modules.reassignment.web.ReassignmentTaskComponent.java

/**
 * {@inheritDoc}/*w ww .j a va 2 s .  c  om*/
 */
@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());
    TaskReassignmentConfig config = _taskReassignementConfigService.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:quanlyhocvu.api.web.controller.staff.ManagementNewsController.java

@RequestMapping(value = "update")
public ModelAndView update(HttpServletRequest request) {

    Map<String, Object> model = new HashMap<>();
    NewsDTO news = mongoService.getNewsById(request.getParameter("newsId"));
    if (news != null) {
        news.setContent(request.getParameter("content"));
        news.setTitle(request.getParameter("title"));
        news.setCatalogs(mongoService.getCatalogsFromIds(request.getParameterValues("catalogs")));
        model.put("message", "Cp nht thng tin bn tin thnh cng");
        mongoService.updateNews(news);// w ww  .java  2  s . c o m
        return new ModelAndView("redirect:/guest/home", model);
    }
    model.put("message", "Cp nht thng tin bn tin tht bi");
    return new ModelAndView("redirect:/guest/home", model);
}

From source file:de.berlios.jhelpdesk.web.taglib.PDFLinkTag.java

@Override
public int doStartTag() throws JspException {
    log.debug("doStartTag()");
    StringBuilder sb = new StringBuilder("<a href=\"").append(this.url).append("?format=pdf");
    HttpServletRequest httpServletRequest = (HttpServletRequest) pageContext.getRequest();

    Enumeration<String> paramNames = httpServletRequest.getParameterNames();

    while (paramNames.hasMoreElements()) {
        String _param = paramNames.nextElement();
        if ("format".equalsIgnoreCase(_param)) {
            continue;
        }// www. j a  v  a 2  s  .  c om
        String[] paramValues = httpServletRequest.getParameterValues(_param);
        for (int i = 0; i < paramValues.length; ++i) {
            sb.append("&").append(_param).append("=").append(paramValues[i]);
        }
    }
    sb.append("\">");
    try {
        pageContext.getOut().write(sb.toString());
    } catch (IOException ioex) {
        log.error("Wystapil problem z zapisem do strumienia.", ioex);
    }
    return EVAL_BODY_INCLUDE;
}

From source file:fi.hoski.web.forms.EventServlet.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setCharacterEncoding("UTF-8");

    Event event;/* www  .j  av a2  s.  c  o m*/
    String[] eventKeys = request.getParameterValues("event");
    if (eventKeys == null) {
        log("Event parameter missing");
        sendError(response, HttpServletResponse.SC_BAD_REQUEST,
                "<div id=\"eNoEvent\">Event parameter missing</div>");
        return;
    } else if (Arrays.asList(eventKeys).contains(Event.EVENT_KEY_CHOOSE)) {
        sendError(response, HttpServletResponse.SC_BAD_REQUEST,
                "<div id='eChooseEvent'>Choose the event</div>");
        return;
    }

    int count = 1;
    try {
        for (String eventKey : eventKeys) {
            if (!eventKey.isEmpty()) {
                try {
                    event = eventManager.getEvent(eventKey);
                } catch (Exception e) {
                    log(eventKey);
                    log(e.getMessage(), e);
                    sendError(response, HttpServletResponse.SC_BAD_REQUEST,
                            "<div id=\"eNoEvent\">Event not found</div>");
                    return;
                }

                Reservation reservation = new Reservation(event);

                @SuppressWarnings("unchecked")
                Map<String, String[]> params = (Map<String, String[]>) request.getParameterMap();

                reservation.set(Reservation.CREATOR, request.getRemoteUser());
                reservation.populate(params);
                String[] bk = params.get(Repository.VENEET_KEY);
                if (bk != null) {
                    Key boatKey = KeyFactory.stringToKey(bk[0]);
                    reservation.set(Repository.VENEID, boatKey);
                }

                eventManager.createReservation(reservation, false);
            } else {
                if (count == 1) {
                    sendError(response, HttpServletResponse.SC_BAD_REQUEST,
                            "<div id=\"eNoEvent\">Event key not found</div>");
                    return;
                }
            }
            count++;
        }
    } catch (EntityNotFoundException ex) {
        throw new ServletException(ex);
    } catch (DoubleBookingException ex) {
        if (count == 1) {
            log(ex.getMessage(), ex);
            sendError(response, HttpServletResponse.SC_CONFLICT,
                    "<div id=\"eDoubleBooking\">Double booking.</div>");
        }
    } catch (EventFullException e) {
        if (count == 1) {
            log(e.getMessage(), e);
            sendError(response, HttpServletResponse.SC_CONFLICT, "<div id=\"eEventFull\">Event full.</div>");
        }
    } catch (BoatNotFoundException e) {
        log(e.getMessage(), e);
        sendError(response, HttpServletResponse.SC_CONFLICT, "<div id=\"eBoatNotFound\">Boat not found.</div>");

    } catch (MandatoryPropertyMissingException e) {
        log(e.getMessage(), e);
        sendError(response, HttpServletResponse.SC_CONFLICT, "<div id=\"eMandatoryPropertyMissing\">"
                + e.getMessage() + " mandatory property missing.</div>");

    } catch (ConcurrentModificationException ex) {
        log(ex.getMessage(), ex);
        sendError(response, HttpServletResponse.SC_CONFLICT,
                "<div id=\"eConcurrentModification\">Concurrent modification.</div>");
    }
    response.setContentType("UTF-8");
    response.getWriter().write("Ilmoittautumisesi on vastaanotettu.");
}

From source file:com.controlj.green.istat.web.BookmarkServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //System.out.println("Area Servlet called at:"+new Date());

    resp.setHeader("Expires", "Wed, 01 Jan 2003 12:00:00 GMT");
    resp.setHeader("Cache-Control", "no-cache");
    ServletOutputStream out = resp.getOutputStream();
    try {//  w w w .  java2  s.c  om
        writeLocations(out, req.getParameterValues("bookmarks"), req);
    } catch (Exception e) {
        Logging.LOGGER.println("Unexpected exception:");
        e.printStackTrace(Logging.LOGGER);

        throw new ServletException(e);
    }
    /*
    out.println("[");
    out.println("{ display:'Main Conf Room', id:'mainconf'},");
    out.println("{ display:'Board Room', id:'boardroom'},");
    out.println("{ display:'Room 235', id:'room235'}");
    out.println("]");
    */
}

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

@RequestMapping(method = RequestMethod.POST)
public ModelAndView doPost(final HttpServletRequest request) {
    /* get model params here */
    String dataset_name = request.getParameter("id");
    String userCertificate = request.getParameter("usercertificate");
    String[] file_names = request.getParameterValues("child_id");
    String[] file_urls = request.getParameterValues("child_url");
    String[] endpointInfos = request.getParameterValues("endpointinfos");

    /* get endpoint info here */
    String goUserName = request.getParameter("gousername");
    String endpoint = request.getParameter("endpointdropdown");
    String target = request.getParameter("target");
    String myProxyUserName = request.getParameter("srcmyproxyuser");
    String myProxyUserPass = request.getParameter("srcmyproxypass");
    String myProxyServerStr = request.getParameter("srcmyproxyserver");

    LOG.debug("GOFormView3Controller: Got GO Username " + goUserName);
    LOG.debug("GOFormView3Controller: Got User Certificate " + userCertificate);
    LOG.debug("GOFormView3Controller: Got selected endpoint " + endpoint);
    LOG.debug("GOFormView3Controller: Got selected target " + target);
    LOG.debug("GOFormView3Controller: Got endpointInfos " + endpointInfos);
    LOG.debug("GOFormView3Controller: Source MyProxy User  " + myProxyUserName);
    LOG.debug("GOFormView3Controller: Source MyProxy Pass *****");
    LOG.debug("GOFormView3Controller: Source MyProxy Server  " + myProxyServerStr);

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

    // find the endpointInfo line that matches the endpoint the user selected
    int len = endpointInfos.length;
    String endpointInfo = null;/*from   w w w .  j av  a2  s. co  m*/
    String searchEndpoint = endpoint + "^^";
    for (int i = 0; i < len; i++) {
        if (endpointInfos[i].startsWith(searchEndpoint)) {
            endpointInfo = endpointInfos[i];
            break;
        }
    }
    System.out.println("User selected endpoint that has the info: " + endpointInfo);
    LOG.debug("User selected endpoint that has the info: " + endpointInfo);

    String destMyProxyServer = null;
    boolean isGlobusConnect = endpointInfo.endsWith("true");

    if (isGlobusConnect == false) {
        String[] pieces = endpointInfo.split("\\^\\^");
        destMyProxyServer = pieces[2];
    }

    if (request.getParameter(GOFORMVIEW_MODEL) != null) {
        //shouldn't ever come here
    } else {
        if (isGlobusConnect == true) {
            LOG.debug("GlobusConnect Endpoint detected");
            model.put(GOFORMVIEW_GO_CONNECT, "true");
        }
        model.put(GOFORMVIEW_DEST_MYPROXY_SERVER, destMyProxyServer);
        model.put(GOFORMVIEW_FILE_URLS, file_urls);
        model.put(GOFORMVIEW_FILE_NAMES, file_names);
        model.put(GOFORMVIEW_USER_CERTIFICATE, userCertificate);
        model.put(GOFORMVIEW_DATASET_NAME, dataset_name);
        model.put(GOFORMVIEW_DEST_TARGET_PATH, target);
        model.put(GOFORMVIEW_DEST_ENDPOINT_INFO, endpointInfo);
        model.put(GOFORMVIEW_GO_USERNAME, goUserName);
        model.put(GOFORMVIEW_MYPROXY_SERVER, myProxyServerStr);
        model.put(GOFORMVIEW_SRC_MYPROXY_USER, myProxyUserName);
        model.put(GOFORMVIEW_SRC_MYPROXY_PASS, myProxyUserPass);
    }

    // NOTE: We have the ability to skip this page if target is
    // Globus Connect rather than using the above method that
    // displays text.  This method should override the above
    // safely.
    // NOT READY JUST YET: always go to step 3 for now
    //
    //if myproxy is required then navigate to the myproxy prompt page
    //         if (isGlobusConnect == false)
    //         {
    return new ModelAndView("goformview4", model);
    //         } 
    //otherwise go to the confirmation page
    //         else
    //         {
    //             return new ModelAndView("goformview4", model);
    //         }
}

From source file:org.openmrs.scheduler.web.controller.SchedulerFormController.java

/**
 * @see org.springframework.web.servlet.mvc.SimpleFormController#processFormSubmission(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 * @should not throw null pointer exception if repeat interval is null
 *//*w  w w  .  java 2  s .c  o  m*/
@Override
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {

    TaskDefinition task = (TaskDefinition) command;

    // assign the properties to the task
    String[] names = request.getParameterValues("propertyName");
    String[] values = request.getParameterValues("propertyValue");

    Map<String, String> properties = new HashMap<String, String>();

    if (names != null) {
        for (int x = 0; x < names.length; x++) {
            if (names[x].length() > 0) {
                properties.put(names[x], values[x]);
            }
        }
    }

    task.setProperties(properties);

    // if the user selected a different repeat interval unit, fix repeatInterval
    String units = request.getParameter("repeatIntervalUnits");
    Long interval = task.getRepeatInterval();
    if (interval != null) {
        if ("minutes".equals(units)) {
            interval = interval * 60;
        } else if ("hours".equals(units)) {
            interval = interval * 60 * 60;
        } else if ("days".equals(units)) {
            interval = interval * 60 * 60 * 24;
        }

        task.setRepeatInterval(interval);
    } else {
        task.setRepeatInterval(0L);
    }

    return super.processFormSubmission(request, response, task, errors);
}

From source file:org.tsugi.jpa.controllers.TsugiController.java

@RequestMapping({ "", "/" })
public String home(HttpServletRequest req, Principal principal, Model model) {
    commonModelPopulate(req, principal, model);

    Enumeration<String> parameterNames = req.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String paramName = parameterNames.nextElement();
        System.out.print(paramName);
        System.out.print("=");
        String[] paramValues = req.getParameterValues(paramName);
        for (int i = 0; i < paramValues.length; i++) {
            String paramValue = paramValues[i];
            if (i > 0)
                System.out.print(", ");
            System.out.print(paramValue);
        }//from   ww  w  . ja  v a2  s.c  o m
        System.out.println();
    }

    model.addAttribute("name", "tsugi");
    req.getSession().setAttribute("login", "oauth");
    // LTIRequest ltiRequest = (LTIRequest) req.getAttribute(LTIRequest.class.getName());
    LTIRequest ltiRequest = new LTIRequest(req, allRepositories, false);
    System.out.println("LTI Request=" + ltiRequest.toString());
    if (ltiRequest != null) {
        model.addAttribute("lti", true);
        model.addAttribute("ltiContext", ltiRequest.getLtiContextId());
        model.addAttribute("ltiUser", ltiRequest.getLtiUserDisplayName());
        model.addAttribute("ltiLink", ltiRequest.getLtiLinkId());
    }
    return "tsugi"; // name of the template
}

From source file:gov.nih.nci.cagrid.opensaml.provider.BrowserProfileProvider.java

/**
 * @see gov.nih.nci.cagrid.opensaml.SAMLBrowserProfile#receive(javax.servlet.http.HttpServletRequest)
 *//*from   w w w  .j  a  v a 2  s  . c o  m*/
public BrowserProfileRequest receive(HttpServletRequest requestContext) throws UnsupportedProfileException {
    BrowserProfileRequest bpr = new BrowserProfileRequest();
    bpr.SAMLResponse = requestContext.getParameter("SAMLResponse");
    if (bpr.SAMLResponse == null) {
        bpr.SAMLArt = requestContext.getParameterValues("SAMLart");
        if (bpr.SAMLArt == null || bpr.SAMLArt.length == 0)
            throw new UnsupportedProfileException(
                    "no SAMLResponse or SAMLart parameters supplied in HTTP request");
    }
    bpr.TARGET = requestContext.getParameter("TARGET");
    return bpr;
}