Example usage for javax.servlet.http HttpServletRequest getParameterMap

List of usage examples for javax.servlet.http HttpServletRequest getParameterMap

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterMap.

Prototype

public Map<String, String[]> getParameterMap();

Source Link

Document

Returns a java.util.Map of the parameters of this request.

Usage

From source file:adminServlets.AddFlowerServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*from w  ww. jav a  2s.  c  o  m*/
        FlowerService flowerService = new FlowerService();
        Flower flower = new Flower();
        BeanUtils.populate(flower, request.getParameterMap());
        if (flowerService.addFlower(flower))
            response.sendRedirect(getServletContext().getRealPath("/") + "AdminView/FlowerAddition.jsp");
    } catch (IllegalAccessException ex) {
        Logger.getLogger(AddFlowerServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException ex) {
        Logger.getLogger(AddFlowerServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.netspective.sparx.form.DialogContextUtils.java

/**
 * Copy any request parameters or attributes that match field names in the dialog
 *//*w  w  w  . jav  a 2s .  com*/
public void populateFieldValuesFromRequestParamsAndAttrs(DialogContext dc) {
    HttpServletRequest request = dc.getHttpRequest();
    Map params = request.getParameterMap();
    DialogFieldStates fieldStates = dc.getFieldStates();
    Iterator i = params.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        String name = (String) entry.getKey();
        DialogField.State state = fieldStates.getState(name, null);
        if (state != null) {
            String[] values = (String[]) entry.getValue();
            state.getValue().setValue(values);
        }
    }

    Enumeration e = request.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        DialogField.State state = fieldStates.getState(name, null);
        if (state != null)
            state.getValue().setValue(request.getAttribute(name));
    }
}

From source file:io.kamax.mxisd.controller.identity.v1.InvitationController.java

@RequestMapping(value = "/store-invite", method = POST)
String store(HttpServletRequest request, @RequestParam String sender, @RequestParam String medium,
        @RequestParam String address, @RequestParam("room_id") String roomId) {
    Map<String, String> parameters = new HashMap<>();
    for (String key : request.getParameterMap().keySet()) {
        parameters.put(key, request.getParameter(key));
    }//from   www  . ja va  2 s  . c  o  m
    IThreePidInvite invite = new ThreePidInvite(new MatrixID(sender), medium, address, roomId, parameters);
    IThreePidInviteReply reply = mgr.storeInvite(invite);

    return gson.toJson(new ThreePidInviteReplyIO(reply, keyMgr.getPublicKeyBase64(keyMgr.getCurrentIndex()),
            srvCfg.getPublicUrl()));
}

From source file:com.iterzp.momo.filter.EncodingConvertFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    if (request.getMethod().equalsIgnoreCase("GET")) {
        for (Iterator<String[]> iterator = request.getParameterMap().values().iterator(); iterator.hasNext();) {
            String[] parames = iterator.next();
            for (int i = 0; i < parames.length; i++) {
                try {
                    parames[i] = new String(parames[i].getBytes(fromEncoding), toEncoding);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }//  w ww. j a  va  2 s . c  om
            }
        }
    }
    filterChain.doFilter(request, response);
}

From source file:com.sun.j2ee.blueprints.waf.controller.web.flow.handlers.ClientStateFlowHandler.java

public String processFlow(HttpServletRequest request) throws FlowHandlerException {

    String forwardScreen = request.getParameter("referring_screen");
    // de-serialize the request attributes.
    Map params = (Map) request.getParameterMap();
    HashMap newParams = new HashMap();
    String cacheId = request.getParameter("cacheId");
    if (!params.isEmpty()) {
        Iterator it = params.keySet().iterator();
        // put the request attributes stored in the session in the request
        while (it.hasNext()) {
            String key = (String) it.next();
            if (key.startsWith(cacheId + "_attribute_")) {
                String[] values = (String[]) params.get(key);
                String valueString = values[0];
                byte[] bytes = Base64.decode(valueString.getBytes());
                try {
                    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
                    Object requestObject = requestObject = ois.readObject();
                    ois.close();//from   ww  w.ja v a 2 s.c o m
                    // put the de-serialized object back into the request
                    String requestObjectKey = key.substring((cacheId + "_attribute_").length(), key.length());
                    request.setAttribute(requestObjectKey, requestObject);
                } catch (java.io.OptionalDataException ode) {
                    System.err.println("ClientCacheLinkFlowHandler caught: " + ode);
                } catch (java.lang.ClassNotFoundException cnfe) {
                    System.err.println("ClientCacheLinkFlowHandler caught: " + cnfe);
                } catch (java.io.IOException iox) {
                    System.err.println("ClientCacheLinkFlowHandler caught: " + iox);
                }
            }
        }
    }
    return forwardScreen;
}

From source file:com.education.lessons.ui.server.login.OpenIDLoginController.java

/**
 * Handles OpenID login verification.<br>
 * Determines whether the user is already a member (performs sign-in) or not
 * (initiates sign-up). In either case, the control is transferred to the
 * client.//from  w w  w .  jav  a 2 s.c  om
 */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/verify")
public ModelAndView doVerify(HttpServletRequest request) {
    String requestURL = getRequestURL(request, true);
    Map<String, String[]> parameterMap = request.getParameterMap();
    Object discovery = request.getSession().getAttribute(DISCOVERY_ATTR);

    ResponseData responseData = getOpenIDService().verifyResponse(requestURL, parameterMap, discovery);

    // look up for existing user
    User user = getLoginService().findUserByOpenID(responseData.getIdentifier());
    ModelAndView mav = new ModelAndView("/login/openid/verify");

    if (user != null) {
        // user found; perform sign-in
        signIn(request.getSession(), user);
    } else {
        // create user ...
        user = new User();
        user.setNickname(responseData.getAttributes().get("nickname"));
        user.setFullname(responseData.getAttributes().get("fullname"));
        user.setEmail(responseData.getAttributes().get("email"));
        user.setPassword("123");
        user.setAdmin(Boolean.FALSE);
        getLoginService().createUserWithOpenID(user, responseData.getIdentifier());
        user = getLoginService().findUserByOpenID(responseData.getIdentifier());
        signIn(request.getSession(), user);
    }

    return mav;
}

From source file:it.cilea.osd.jdyna.controller.FormEditTabController.java

@Override
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    ET object = (ET) command;/*from w ww . j av  a2s  . co m*/
    Map<String, String> maprequest = request.getParameterMap();

    if (maprequest.containsKey(SUBMIT_DECOUPLE)) {
        applicationService.decoupleEditTabByDisplayTab(object.getDisplayTab().getId(), tabEditClass);
    }
    if (maprequest.containsKey(SUBMIT_HOOKUP)) {
        String hookit = request.getParameter("hookedtab");
        T tab = applicationService.getTabByShortName(tabClass, hookit);
        if (tab == null) {
            return new ModelAndView(getFormView(), "tab", object);
        }
        applicationService.saveOrUpdate(tabEditClass, object);
        applicationService.hookUpEditTabToDisplayTab(object.getId(), tab.getId(), tabEditClass);
    }
    return super.processFormSubmission(request, response, command, errors);
}

From source file:CPD4414Assign3.ProductServlet.java

protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Set<String> keySet = request.getParameterMap().keySet();
    try (PrintWriter out = response.getWriter()) {
        Connection conn = getConnection();
        if (keySet.contains("productID") && keySet.contains("name") && keySet.contains("description")
                && keySet.contains("quantity")) {
            PreparedStatement pstmt = conn.prepareStatement("UPDATE `product` SET `name`='"
                    + request.getParameter("name") + "',`description`='" + request.getParameter("description")
                    + "',`quantity`=" + request.getParameter("quantity") + " WHERE `productID`="
                    + request.getParameter("productID"));
            try {
                pstmt.executeUpdate();/*from   w  w w  . ja v a 2  s .  co m*/
                doGet(request, response); //shows updated row
            } catch (SQLException ex) {
                Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
                out.println("Error updating values.");
                response.setStatus(500);
            }
        } else {
            out.println("Error: Not enough data to update");
            response.setStatus(500);
        }
    } catch (SQLException ex) {
        Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:controler.category.AddCategoryServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Category category = new Category();
    CategoryDAO categoryDAO = new CategoryDAO();
    try {/* w  w  w  .  j  av  a  2s  .  c  o m*/
        BeanUtils.populate(category, request.getParameterMap());
        if (categoryDAO.connect()) {
            categoryDAO.addCategory(category);
        }

    } catch (IllegalAccessException ex) {
        Logger.getLogger(AddCategoryServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException ex) {
        Logger.getLogger(AddCategoryServlet.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        categoryDAO.disconnect();
    }

}

From source file:CPD4414Assign3.ProductServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Set<String> keySet = request.getParameterMap().keySet();
    try (PrintWriter out = response.getWriter()) {
        Connection conn = getConnection();
        if (keySet.contains("name") && keySet.contains("description") && keySet.contains("quantity")) {
            PreparedStatement pstmt = conn
                    .prepareStatement("INSERT INTO `product`(`productID`, `name`, `description`, `quantity`) "
                            + "VALUES (" + "null, '" + request.getParameter("name") + "', '"
                            + request.getParameter("description") + "', " + request.getParameter("quantity")
                            + ");");
            try {
                pstmt.executeUpdate();/*from   ww w  .  j ava 2 s . co m*/
                request.setAttribute("productID", 2);
                request.getParameter("productID");
                doGet(request, response); //shows updated row
            } catch (SQLException ex) {
                Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
                out.println("Error with inserting values.");
                response.setStatus(500);
            }
        } else {
            out.println("Error: Not enough data to input");
            response.setStatus(500);
        }
    } catch (SQLException ex) {
        Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}