Example usage for javax.servlet.http HttpServletRequest getParameterNames

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

Introduction

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

Prototype

public Enumeration<String> getParameterNames();

Source Link

Document

Returns an Enumeration of String objects containing the names of the parameters contained in this request.

Usage

From source file:dk.cphbusiness.codecheck.web.Upload.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request//from w ww . j a v a2s  .  c  o m
 * @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 {
    Enumeration<String> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String name = paramNames.nextElement();
        String value = request.getParameter(name);
        System.out.println(name + ": " + value);
    }
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (!isMultipart) {
        try (PrintWriter out = response.getWriter()) {
            out.println("Error: not a multipart request.");
            return;
        }
    }

    // Create a factory for disk-based file items
    DiskFileItemFactory factory = new DiskFileItemFactory();

    // Configure a repository (to ensure a secure temp location is used)
    //ServletContext servletContext = this.getServletConfig().getServletContext();
    //File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
    File repository = new File(Config.UPLOAD_FOLDER);
    factory.setRepository(repository);

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    int taskID = -1;
    try {
        // Parse the request
        List<FileItem> items = upload.parseRequest(request);
        FileItem ft = null;
        for (FileItem item : items) {
            if (item.isFormField()) {
                if ("TaskID".equals(item.getFieldName())) {
                    taskID = Integer.parseInt(item.getString());
                }
            } else {
                ft = item;
            }
        }
        if (taskID > 0 && ft != null) {
            int reportID = DBUtil.createReport(taskID);
            String fileName = "HandIn_" + reportID + ".jar";
            ft.write(new File(Config.UPLOAD_FOLDER + fileName));
            Task task = DBUtil.getTask(taskID);
            CodeChecker codeChecker = new CodeChecker(reportID, task, fileName);
            Thread t = new Thread(codeChecker);
            t.start();
            //codeChecker.run();
            response.sendRedirect("/CodeCheckWeb/ShowReport?ReportID=" + reportID);
        }
    } catch (FileUploadException ex) {
        Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.netpace.cms.sso.filter.AlfrescoOpenSSOFilter.java

private boolean isLoginRequest(HttpServletRequest request) {
    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameter = (String) parameterNames.nextElement();
        String[] string = request.getParameterValues(parameter);
        for (int i = 0; i < string.length; i++) {
            if (string[i] != null && string[i].contains(":login")) {
                return true;
            }//from   w  w w . j a  v  a 2 s  .  c o m
        }
    }
    return false;
}

From source file:com.netpace.cms.sso.filter.AlfrescoOpenSSOFilter.java

private boolean isLogoutRequest(HttpServletRequest request) {
    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameter = (String) parameterNames.nextElement();
        String[] string = request.getParameterValues(parameter);
        for (int i = 0; i < string.length; i++) {
            if (string[i] != null && string[i].contains(":logout")) {
                return true;
            }//w  ww.  j  a v  a  2  s.c o m
        }
    }
    return false;
}

From source file:org.opensprout.osaf.web.support.PageNavigation.java

@SuppressWarnings("unchecked")
private String extractSearchParamsExceptPageParams(HttpServletRequest req) {
    StringBuilder param = new StringBuilder();

    try {/*from w  w  w  .  j a  v  a  2s  . c o m*/
        Enumeration<String> e = req.getParameterNames();
        while (e.hasMoreElements()) {
            String key = e.nextElement();

            if (key.equals(PAGE_PARAM_NAME) || key.equals(PAGESIZE_PARAM_NAME) || key.equals(ORDER_PARAM_NAME))
                continue;

            String value = req.getParameter(key);
            param.append("&");
            param.append(key);
            param.append("=");
            param.append(URLEncoder.encode(value, "EUC-KR"));
        }

        return param.toString();
    } catch (UnsupportedEncodingException e1) {
        throw new RuntimeException(e1);
    }
}

From source file:com.app.kmsystem.util.StringUtils.java

/**
 * Return an ordered map of request parameters from the given request.
 *
 * @param request the servlet request to obtain request parameters from
 * @return the ordered map of request parameters
 *///from w w  w  .  ja  v a  2 s .  c  o  m
@SuppressWarnings("unchecked")
public static Map<String, String> getRequestParameters(HttpServletRequest request) {

    TreeMap<String, String> requestParams = new TreeMap<String, String>();

    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String name = paramNames.nextElement().toString();

        String[] values = request.getParameterValues(name);
        HtmlStringBuffer valsBuffer = new HtmlStringBuffer(32);

        if (values.length == 1) {
            valsBuffer.append(values[0]);

        } else {
            for (int i = 0; i < values.length; i++) {
                if (i == 0) {
                    valsBuffer.append("[");
                }
                valsBuffer.append(values[i]);
                if (i == values.length - 1) {
                    valsBuffer.append("]");
                } else {
                    valsBuffer.append(",");
                }
            }
        }
        requestParams.put(name, valsBuffer.toString());
    }

    return requestParams;
}

From source file:co.id.app.sys.util.StringUtils.java

/**
 * Return an ordered map of request parameters from the given request.
 *
 * @param request the servlet request to obtain request parameters from
 * @return the ordered map of request parameters
 *//*from  w  w w .  ja v  a2  s . c  o  m*/
@SuppressWarnings("rawtypes")
public static Map<String, String> getRequestParameters(HttpServletRequest request) {

    TreeMap<String, String> requestParams = new TreeMap<String, String>();

    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String name = paramNames.nextElement().toString();

        String[] values = request.getParameterValues(name);
        HtmlStringBuffer valsBuffer = new HtmlStringBuffer(32);

        if (values.length == 1) {
            valsBuffer.append(values[0]);

        } else {
            for (int i = 0; i < values.length; i++) {
                if (i == 0) {
                    valsBuffer.append("[");
                }
                valsBuffer.append(values[i]);
                if (i == values.length - 1) {
                    valsBuffer.append("]");
                } else {
                    valsBuffer.append(",");
                }
            }
        }
        requestParams.put(name, valsBuffer.toString());
    }

    return requestParams;
}

From source file:com.glaf.core.util.RequestUtils.java

/**
 * request??//from   w ww . j a  v a 2  s.c  om
 * 
 * @param request
 * @return
 */
public static Map<String, Object> getParameterMap(HttpServletRequest request) {
    Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
    Enumeration<?> enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) {
        String paramName = (String) enumeration.nextElement();
        String paramValue = getParameter(request, paramName);
        if (StringUtils.isNotEmpty(paramName) && StringUtils.isNotEmpty(paramValue)) {
            if (paramValue.equalsIgnoreCase("null")) {
                continue;
            }
            dataMap.put(paramName, paramValue);
            String tmp = paramName.trim().toLowerCase();
            if (tmp.indexOf("date") > 0) {
                try {
                    Date date = DateUtils.toDate(paramValue);
                    dataMap.put(tmp, date);
                } catch (Exception ex) {
                }
            } else if (tmp.startsWith("x_encode_")) {
                String name = StringTools.replace(paramName, "x_encode_", "");
                dataMap.put(name, decodeString(paramValue));
            } else if (tmp.startsWith("x_collection_")) {
                String name = StringTools.replace(paramName, "x_collection_", "");
                dataMap.put(name, StringTools.split(paramValue));
            }
        }
    }
    return dataMap;
}

From source file:edu.cornell.mannlib.vedit.controller.BaseEditController.java

protected void populateBeanFromParams(Object bean, HttpServletRequest request) {
    Map params = request.getParameterMap();
    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String key = "";
        try {//  w  w  w  .  jav  a2 s.  c om
            key = (String) paramNames.nextElement();
        } catch (ClassCastException cce) {
            log.error("populateBeanFromParams() could not cast parameter name to String");
        }
        String value = "";
        if (key.equals(MULTIPLEXED_PARAMETER_NAME)) {
            String multiplexedStr = request.getParameterValues(key)[0];
            Map paramMap = FormUtils.beanParamMapFromString(multiplexedStr);
            Iterator paramIt = paramMap.keySet().iterator();
            while (paramIt.hasNext()) {
                String param = (String) paramIt.next();
                String demultiplexedValue = (String) paramMap.get(param);
                FormUtils.beanSet(bean, param, demultiplexedValue);
            }

        } else {
            try {
                value = (String) request.getParameterValues(key)[0];
            } catch (ClassCastException cce) {
                try {
                    value = ((Integer) params.get(key)).toString();
                } catch (ClassCastException ccf) {
                    log.error("populateBeanFromParams() could not cast parameter name to String");
                }
            }
            FormUtils.beanSet(bean, key, value);
        }
    }
}

From source file:com.glaf.core.util.RequestUtils.java

/**
 * request??/*w  w  w .ja  v a  2s. co m*/
 * 
 * @param request
 * @return
 */
public static Map<String, Object> getParameterMap(HttpServletRequest request, String prefix) {
    Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
    Enumeration<?> enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) {
        String paramName = (String) enumeration.nextElement();
        String paramValue = getParameter(request, paramName);
        if (paramName != null && paramValue != null) {
            if (paramValue.trim().length() > 0 && !"null".equalsIgnoreCase(paramValue)) {
                if (!paramName.startsWith(prefix)) {
                    continue;
                }
                paramName = paramName.substring(prefix.length());
                dataMap.put(paramName, paramValue);
            }
        }
    }
    return dataMap;
}

From source file:CreateGameServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    JSONObject json = new JSONObject();

    Enumeration paramNames = request.getParameterNames();
    String params[] = new String[1];
    int i = 0;/*from ww w .  j  a  v a2 s.  co  m*/
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        String[] paramValues = request.getParameterValues(paramName);
        params[i] = paramValues[0];
        i++;
    }
    //System.out.println("param0->"+params[0]);

    DatabaseHandler db = new DatabaseHandler();

    conn = db.makeConnection();

    try {
        stmt = conn.createStatement();

        String query = "INSERT INTO game (hoster,nameplayer1) VALUES (\"" + params[0] + "\",\"" + params[0]
                + "\")";
        //System.out.println(query);

        int updatedRows = stmt.executeUpdate(query);
        if (updatedRows == 1) {
            json.put("reply", "done");
        } else {
            json.put("reply", "undone");
        }

        query = "SELECT id FROM game WHERE hoster=\"" + params[0] + "\"";
        PreparedStatement prstmt = conn.prepareStatement(query);
        ResultSet rs = prstmt.executeQuery();
        String id = "0";
        while (rs.next()) {
            id = rs.getString("id");
        }
        //System.out.println("id-> "+id);
        if (!id.equals("0")) {
            json.put("gameid", id);
        }

    } catch (SQLException ex) {
        Logger.getLogger(CreateGameServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(json.toString());

    db.closeAllConnections(conn, stmt);

}