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:gsn.http.ac.ParameterSet.java

/*************************************************************************************************/

/* constructor for processing parameters of a normal form */
public ParameterSet(HttpServletRequest req) {
    paramset = new Hashtable();
    Enumeration myenum = req.getParameterNames();
    while (myenum.hasMoreElements()) {
        String name = (String) myenum.nextElement();
        String values[] = req.getParameterValues(name);
        if (values != null) {
            if (values.length <= 1) {
                paramset.put(name, req.getParameter(name));

            }/*w w  w . j  ava  2  s . c  o m*/
        } else {
            paramset.put(name, req.getParameter(name));

        }
    }
}

From source file:com.autobizlogic.abl.mgmt.ConsoleServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, java.io.IOException {

    Map<String, String> args = new HashMap<String, String>();
    Enumeration<String> paramNames = req.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        String paramValue = req.getParameter(paramName);
        if (paramValue == null || paramValue.length() == 0)
            paramValue = null;/*ww w. j a  v a 2s  . com*/
        args.put(paramName, paramValue);
    }

    Map<String, Object> result = null;
    String areaName = args.get("area");
    if (areaName.equals("SessionFactory"))
        result = SessionFactoryService.service(args);
    else if (areaName.equals("ClassMetadata"))
        result = ClassMetadataService.service(args);
    else if (areaName.equals("Transactions"))
        result = TransactionService.service(args);
    else if (areaName.equals("Performance"))
        result = PerformanceService.service(args);
    else if (areaName.equals("Dependency"))
        result = DependencyService.service(args);

    if (result == null)
        return;

    resp.setContentType("application/json");
    String resStr = JSONValue.toJSONString(result);
    PrintWriter out = resp.getWriter();
    out.print(resStr);
}

From source file:RegistrationServlet.java

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

    Enumeration paramNames = request.getParameterNames();
    String params[] = new String[3];
    int i = 0;/*from   ww w . j a va  2 s  . c o m*/
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        //System.out.println("ParamName : " +paramName);

        String[] paramValues = request.getParameterValues(paramName);
        params[i] = paramValues[0];
        //System.out.println("ParamValue : " +params[i]);

        i++;
    }

    DatabaseHandler db = new DatabaseHandler();

    conn = db.makeConnection();
    try {
        stmt = conn.createStatement();

        //params[0]=password,params[1]=name,params[2]=email
        String query = "INSERT INTO user (name,email,password) VALUES (\"" + params[1] + "\",\"" + params[2]
                + "\",\"" + params[0] + "\")";
        //System.out.println(query);

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

    } catch (SQLException ex) {
        Logger.getLogger(RegistrationServlet.class.getName()).log(Level.SEVERE, null, ex);
    }

    //System.out.println(updatedRows);
    //System.out.println(json);

    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(json.toString());

    //closing mysql connection (now done in DatanaseHandler class)
    db.closeAllConnections(conn, stmt);

}

From source file:com.github.dbourdette.otto.web.controller.api.ApiController.java

/**
 * Since we are using @Async in our RemoteEventsFacade we need to deep copy map of parameters from request.
 * At least tomcat reuse request objects and map would be empty when @Async code is invoked.
 *///w  ww. j  a va 2s  .  com
private Map<String, String> copyParams(HttpServletRequest request) {
    Map<String, String> params = new HashMap<String, String>();

    Enumeration<String> names = request.getParameterNames();

    while (names.hasMoreElements()) {
        String name = names.nextElement();

        params.put(name, request.getParameter(name));
    }

    return params;
}

From source file:productClass.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * Select statement for the database connect to retrieve values
 * //from www . j a v a  2 s.co m
 * @param request servlet request
 * @param response servlet response
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
    try (PrintWriter out = response.getWriter()) {
        if (!request.getParameterNames().hasMoreElements()) {
            out.println(getResults("SELECT * FROM product"));
        } else {
            int productID = Integer.parseInt(request.getParameter("productID"));
            out.println(getResults("SELECT * FROM product WHERE productID = ?", String.valueOf(productID)));
        }
    } catch (IOException ex) {
        Logger.getLogger(productClass.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.blackducksoftware.integration.hub.teamcity.server.global.HubGlobalServerConfigController.java

private boolean isTestConnectionRequest(final HttpServletRequest request) {
    if (!request.getParameterNames().hasMoreElements()) {
        return false;
    }//from w  ww  .j  av a 2 s.  c o m
    final String testConnectionParamValue = request.getParameter("testConnection");
    return Boolean.valueOf(testConnectionParamValue);
}

From source file:com.blackducksoftware.integration.hub.teamcity.server.global.HubGlobalServerConfigController.java

private boolean isSavingRequest(final HttpServletRequest request) {
    if (!request.getParameterNames().hasMoreElements()) {
        return false;
    }// ww  w.ja v  a 2s  .c  o m
    final String savingParamValue = request.getParameter("saving");
    return Boolean.valueOf(savingParamValue);
}

From source file:org.freeeed.ep.web.BaseController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    this.request = request;
    this.response = response;

    valueStack = new HashMap<String, Object>();
    Enumeration<String> en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String param = en.nextElement();
        valueStack.put(param, request.getParameter(param));
    }//from   w  ww  .  j a v a 2 s.co m

    ModelAndView modelAndView = execute();

    if (addValueStackToModel()) {
        modelAndView.addAllObjects(valueStack);
    }

    return modelAndView;
}

From source file:JoinGameServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    Enumeration paramNames = request.getParameterNames();
    String params[] = new String[3];
    int i = 0;/*from  w w w .j  av a  2 s  .co  m*/
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        //System.out.println("ParamName : " +paramName);

        String[] paramValues = request.getParameterValues(paramName);
        params[i] = paramValues[0];
        //System.out.println("ParamValue : " +params[i]);

        i++;
    }
    //System.out.println("param0->"+params[0]);
    //System.out.println("param1->"+params[1]);
    //param0->gameid,param1->name

    DatabaseHandler db = new DatabaseHandler();

    conn = db.makeConnection();

    String query = "SELECT * FROM game WHERE id=" + params[0];
    //System.out.println(query);

    PreparedStatement prStmt;
    try {
        prStmt = conn.prepareStatement(query);
        ResultSet rs = prStmt.executeQuery();

        if (rs.next()) {
            String count = rs.getString("playercount");
            count = String.valueOf(Integer.parseInt(count) + 1);

            String qry = "UPDATE game SET nameplayer" + count + "=\"" + params[1] + "\",playercount=\"" + count
                    + "\" WHERE id=\"" + params[0] + "\"";
            //System.out.println(qry);

            stmt = conn.createStatement();
            int updatedRows = stmt.executeUpdate(qry);
            if (updatedRows == 1) {
                json.put("reply", "done");
                json.put("actionid", count);
                //setting next player action to 1 to start bet
                if (Integer.parseInt(count) == 4) {
                    qry = "UPDATE game SET turn=1,nextactionuserid=1 WHERE id=\"" + params[0] + "\"";
                    stmt.execute(qry);
                }
            } else {
                json.put("reply", "undone");
            }
        }

        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(json.toString());

    } catch (SQLException ex) {
        Logger.getLogger(JoinGameServlet.class.getName()).log(Level.SEVERE, null, ex);
    }

    db.closeAllConnections(conn, stmt);

}

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

/**
 * ?/*from  w ww.  j  a v a  2 s  .c o m*/
 * 
 * @param request
 */
public static void setRequestParameterToAttribute(HttpServletRequest request) {
    request.setAttribute("contextPath", request.getContextPath());
    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 (request.getAttribute(paramName) != null) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("method", paramName)) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("action", paramName)) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("actionType", paramName)) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("reset", paramName)) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("submit", paramName)) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("button", paramName)) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("cancel", paramName)) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("parent", paramName)) {
                continue;
            } else if (StringUtils.equalsIgnoreCase("hasPermission", paramName)) {
                continue;
            }
            request.setAttribute(paramName, paramValue);
        }
    }
}