Example usage for javax.servlet.http HttpServletRequest getParameter

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

Introduction

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

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:com.krawler.esp.servlets.SuperAdminServlet.java

public static String signUp(Connection conn, HttpServletRequest request, HttpServletResponse response)
        throws ServiceException {
    String status = "";
    ResultSet frs = null, ars = null;
    PreparedStatement pstmt = null, fpstmt = null, apstmt = null;
    double val = 0.0;
    String companyid = UUID.randomUUID().toString();
    java.util.Date d = new java.util.Date();
    java.sql.Timestamp today = new Timestamp(d.getTime());
    DbUtil.executeUpdate(conn, "insert into company(companyid, companyname, createdon) values (?,?,?);",
            new Object[] { companyid, request.getParameter("company-name"), today });
    String userid = UUID.randomUUID().toString();
    DbUtil.executeUpdate(conn, "insert into userlogin(userid, username, password, authkey) values (?,?,?,?);",
            new Object[] { userid, request.getParameter("newuserid"), request.getParameter("newpassword"),
                    "" });
    DbUtil.executeUpdate(conn, "insert into users(userid,companyid, emailid, image) values (?,?,?,?);",
            new Object[] { userid, companyid, request.getParameter("email"), "" });
    try {/*from   ww  w .  j  a v a 2 s.  co m*/
        fpstmt = conn.prepareStatement("SELECT featureid FROM featurelist");
        frs = fpstmt.executeQuery();
        while (frs.next()) {
            apstmt = conn.prepareStatement("SELECT activityid FROM activitieslist WHERE featureid=?");
            apstmt.setInt(1, frs.getInt("featureid"));
            ars = apstmt.executeQuery();
            while (ars.next()) {
                val += Math.pow(2, Double.parseDouble(ars.getString("activityid")));
            }
            pstmt = conn.prepareStatement(
                    "INSERT INTO userpermissions (userid, featureid, permissions) VALUES (?,?,?)");
            pstmt.setString(1, userid);
            pstmt.setInt(2, frs.getInt("featureid"));
            pstmt.setInt(3, (int) val);
            pstmt.executeUpdate();

            val = 0.0;
        }
    } catch (SQLException e) {
        throw ServiceException.FAILURE("signup.confirmSignup", e);
    } finally {
        DbPool.closeStatement(pstmt);
    }
    status = "success";
    return status;
}

From source file:ste.web.beanshell.jetty.BeanShellUtils.java

public static void setup(final Interpreter interpreter, final HttpServletRequest request,
        final HttpServletResponse response) throws EvalError, IOException {
    //// w  w w  . ja v a 2 s .  c o  m
    // Set attributes as script variables
    //
    String k, key;
    for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) {
        k = (String) e.nextElement();
        key = normalizeVariableName(k);
        interpreter.set(key, request.getAttribute(k));
    }

    //
    // Set request parameters as script variables. Note that parameters
    // override attributes
    //
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
        k = (String) e.nextElement();
        key = normalizeVariableName(k);
        interpreter.set(key, request.getParameter(k));
    }

    interpreter.set(VAR_REQUEST, request);
    interpreter.set(VAR_RESPONSE, response);
    interpreter.set(VAR_SESSION, request.getSession(false));
    interpreter.set(VAR_OUT, response.getWriter());
    interpreter.set(VAR_LOG, log);
    if (hasJSONBody(request)) {
        interpreter.set(VAR_BODY, getJSONBody(request.getInputStream()));
    }
}

From source file:ltistarter.lti.LTIRequest.java

/**
 * Creates an LTI composite key which can be used to identify a user session consistently
 *
 * @param request     the incoming request
 * @param sessionSalt the salt (defaults to a big random string)
 * @return the composite string (md5)//from w w w  .jav a 2  s. c  o  m
 */
public static String makeLTICompositeKey(HttpServletRequest request, String sessionSalt) {
    if (StringUtils.isBlank(sessionSalt)) {
        sessionSalt = "A7k254A0itEuQ9ndKJuZ";
    }
    String composite = sessionSalt + "::" + request.getParameter(LTI_CONSUMER_KEY) + "::"
            + request.getParameter(LTI_CONTEXT_ID) + "::" + request.getParameter(LTI_LINK_ID) + "::"
            + request.getParameter(LTI_USER_ID) + "::" + (System.currentTimeMillis() / 1800)
            + request.getHeader("User-Agent") + "::" + request.getContextPath();
    return DigestUtils.md5Hex(composite);
}

From source file:com.liferay.portal.action.LoginAction.java

public static String getLogin(HttpServletRequest req, String paramName, Company company)
        throws PortalException, SystemException {

    String login = req.getParameter(paramName);

    if ((login == null) || (login.equals(StringPool.NULL))) {
        login = GetterUtil.getString(CookieUtil.get(req.getCookies(), CookieKeys.LOGIN));

        if (Validator.isNull(login) && company.getAuthType().equals(CompanyImpl.AUTH_TYPE_EA)) {

            login = "@" + company.getMx();
        }/* w  w w. j a va2 s.  co m*/
    }

    login = XSSUtil.strip(login);

    return login;
}

From source file:com.comcast.cqs.util.Util.java

public static List<String> fillGetAttributesRequests(HttpServletRequest request) {

    // process Attribute.n requests start from 1 ordinal, ignore rest if there is a break

    List<String> attributeNames = new ArrayList<String>();
    String attr = null;/*from  w  w  w.  j  a  v  a  2 s .  c  om*/

    if (request.getParameter(CQSConstants.ATTRIBUTE_NAME) != null) {
        attr = request.getParameter(CQSConstants.ATTRIBUTE_NAME);
        attributeNames.add(attr);
    }

    int index = 1;
    attr = request.getParameter(CQSConstants.ATTRIBUTE_NAME + "." + index);

    while (attr != null) {
        attributeNames.add(attr);
        index++;
        attr = request.getParameter(CQSConstants.ATTRIBUTE_NAME + "." + index);
    }

    return attributeNames;
}

From source file:com.vmware.identity.SharedUtils.java

public static HttpServletRequest buildMockRequestObject(SignableSAMLObject samlObject,
        String relayStateParameter, String sigAlg, String signature, StringBuffer sbRequestUrl,
        String authorization, String sessionId, int tenantId) throws MarshallingException, IOException {

    Cookie[] expectedCookies = new Cookie[] {};
    String tenant = ServerConfig.getTenant(tenantId);

    if (sessionId != null) {
        expectedCookies = new Cookie[] { new Cookie(Shared.getTenantSessionCookieName(tenant), sessionId) };
    }/* w w w  .j  ava 2 s . c o m*/

    // build mock request object
    HttpServletRequest request = createMock(HttpServletRequest.class);
    expect(request.getCookies()).andReturn(expectedCookies).anyTimes();
    if (samlObject instanceof LogoutResponse) {
        expect(request.getParameter(Shared.SAML_RESPONSE_PARAMETER))
                .andReturn(SharedUtils.encodeRequest(samlObject)).anyTimes();
        expect(request.getParameter(Shared.SAML_REQUEST_PARAMETER)).andReturn(null).anyTimes();
    } else {
        expect(request.getHeader(Shared.IWA_AUTH_REQUEST_HEADER)).andReturn(null).anyTimes();
        expect(request.getParameter(Shared.SAML_REQUEST_PARAMETER))
                .andReturn(SharedUtils.encodeRequest(samlObject)).anyTimes();
        expect(request.getParameter(Shared.SAML_RESPONSE_PARAMETER)).andReturn(null).anyTimes();
    }

    expect(request.getParameter(Shared.RELAY_STATE_PARAMETER)).andReturn(relayStateParameter).anyTimes();
    expect(request.getParameter(Shared.SIGNATURE_ALGORITHM_PARAMETER)).andReturn(sigAlg).anyTimes();
    expect(request.getParameter(Shared.SIGNATURE_PARAMETER)).andReturn(signature).anyTimes();
    expect(request.getRequestURL()).andReturn(sbRequestUrl).anyTimes();
    expect(request.getParameter(Shared.REQUEST_AUTH_PARAM)).andReturn(authorization).anyTimes();
    String queryString = Shared.SAML_REQUEST_PARAMETER + "=" + SharedUtils.encodeRequest(samlObject);
    if (relayStateParameter != null) {
        queryString = queryString + "&" + Shared.RELAY_STATE_PARAMETER + "=" + relayStateParameter;
    }
    if (sigAlg != null) {
        queryString = queryString + "&" + Shared.SIGNATURE_ALGORITHM_PARAMETER + "=" + sigAlg;
    }
    if (signature != null) {
        queryString = queryString + "&" + Shared.SIGNATURE_PARAMETER + "=" + signature;
    }
    expect(request.getQueryString()).andReturn(queryString).anyTimes();

    replay(request);
    return request;
}

From source file:com.gtwm.pb.servlets.ServletDataMethods.java

/**
 * Delete the record of 'internaltablename' (or the session table if
 * 'internaltablename'=="") identified by 'rowid' (or the session record if
 * 'rowid'="")/* w ww.j  av  a 2  s . c  o  m*/
 * 
 * @throws ObjectNotFoundException
 *             If either a) table or row id object aren't in the session, b)
 *             there is no record with the given rowId in the table, c)
 *             there is more than one record with the given rowId in the
 *             table
 * @throws DisallowedException
 *             If user doesn't have EDIT_TABLE_DATA privileges
 */
public static void removeRecord(SessionDataInfo sessionData, HttpServletRequest request,
        DatabaseInfo databaseDefn) throws MissingParametersException, ObjectNotFoundException,
        DisallowedException, SQLException, CodingErrorException, CantDoThatException, DataDependencyException {
    // obtain a reference to the table containing the record:
    TableInfo table = ServletUtilMethods.getTableForRequest(sessionData, request, databaseDefn, true);
    // obtain the rowid of the record to be deleted:
    String rowId = request.getParameter("rowid");
    int iRowId = -1;
    if (rowId == null) {
        iRowId = sessionData.getRowId();
    } else {
        try {
            iRowId = Integer.parseInt(rowId);
        } catch (RuntimeException rtex) {
            iRowId = -1;
        } catch (Exception e) {
            iRowId = -1;
        }
    }
    if (iRowId == -1) {
        throw new ObjectNotFoundException(
                "'rowid' was not provided and there is no record identifier in the session");
    }
    String cascadeValueString = request.getParameter("cascadedelete");
    boolean cascade = Helpers.valueRepresentsBooleanTrue(cascadeValueString);
    // having obtained valid parameters, delete the record:
    if (!(databaseDefn.getAuthManager().getAuthenticator().loggedInUserAllowedTo(request,
            PrivilegeType.EDIT_TABLE_DATA, table))) {
        throw new DisallowedException(databaseDefn.getAuthManager().getLoggedInUser(request),
                PrivilegeType.EDIT_TABLE_DATA, table);
    }
    databaseDefn.getDataManagement().removeRecord(request, sessionData, databaseDefn, table, iRowId, cascade);
    ServletDataMethods.logDataChanges(request, databaseDefn, "deleted the record with rowid " + rowId + " from "
            + table.getTableName() + " (" + table.getInternalTableName() + ")");
    // Un-set the session record
    sessionData.setRowId(table, -1);
    sessionData.setLastAppActionRowId(iRowId);
}

From source file:net.duckling.ddl.util.ResourceQuery.java

public static ResourceQuery buildForQuery(HttpServletRequest request, String order) {
    ResourceQuery query = null;//from  w ww .  j a  v  a  2  s  . c om
    String queryType = request.getParameter("queryType");
    queryType = StringUtils.isEmpty(queryType) ? "" : queryType;
    switch (queryType) {
    case "myCreate":
        query = new MyCreateQuery(VWBSession.getCurrentUid(request));
        break;
    case "myStarFiles":
        query = new MyStarFilesQuery(VWBSession.getCurrentUid(request));
        break;
    case "teamRecentChange":
        query = new TeamRecentChangeQuery();
        break;
    case "showFileByType":
    case "fileType":
        query = new FileTypeQuery();
        break;
    case "tagQuery":
        String d = request.getParameter("date");
        String all = request.getParameter("tagFilter");
        if ("all".equals(all)) {
            query = new ResourcePathQuery(getRequestRid(request));
            break;
        }
        if (StringUtils.isNotEmpty(d)) {
            query = new ResourceTimeQuery(d);
        } else {
            query = new TagQuery(getTagIds(request));
        }
        break;
    case "ExceptFolder":
        query = new ExceptFolderQuery();
        break;
    default:
        query = new ResourcePathQuery(getRequestRid(request));
        break;
    }
    query.setSortType(request.getParameter("sortType"));
    query.setKeyword(request.getParameter("keyWord"));
    query.setDate(request.getParameter("date"));
    query.setSize(getMaxSize(request));
    query.setTagIds(WebParamUtil.getIntegerValues(request, "tag"));
    query.setOffset(getInteger(request.getParameter("begin"), 0));
    query.setFileType(request.getParameter("fileType"));
    if (StringUtils.isEmpty(query.getFileType())) {
        query.setFileType(request.getParameter("type"));
    }
    query.setOrderType(order);
    query.setTid(VWBContext.getCurrentTid());
    return query;
}

From source file:org.cyberoam.iview.charts.Chart.java

/**
 * Get chart for web application rendering. 
 * @param Request instance used for chart generation process
 * @param out instance used for tool tip image map
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from uri.
 * @param imagehieght used for image height
 * @param imagewidht used for image width
 * @return fileName/* ww  w.jav  a2s . co  m*/
 */
public static String getChartForWeb(HttpServletRequest request, PrintWriter out, ResultSetWrapper rsw,
        int imageWidth, int imageHeight) {
    String fileName = null;
    try {
        int reportID = request.getParameter("reportid") == null ? -1
                : Integer.parseInt(request.getParameter("reportid"));
        JFreeChart chart = Chart.getChart(reportID, rsw, request);

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        //Save the generated Chart image to system temporary directory.
        fileName = ServletUtilities.saveChartAsPNG(chart, imageWidth, imageHeight, info, request.getSession());
        //  Write the tool tip map to GUI.
        org.jfree.chart.ChartUtilities.writeImageMap(out, fileName, info, false);
        out.flush();
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("Chart.getChartForWeb:" + e, e);
    }
    return fileName;
}

From source file:com.dien.upload.server.UploadServlet.java

/**
 * Delete an uploaded file./*from ww w .  ja v a2s . c  o m*/
 * 
 * @param request
 * @param response
 * @return FileItem
 * @throws IOException
 */
protected static FileItem removeUploadedFile(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    String parameter = request.getParameter(UConsts.PARAM_REMOVE);

    FileItem item = findFileItem(getSessionFileItems(request), parameter);
    if (item != null) {
        getSessionFileItems(request).remove(item);
        renderXmlResponse(request, response, XML_DELETED_TRUE);
        logger.debug("UPLOAD-SERVLET (" + request.getSession().getId() + ") removeUploadedFile: " + parameter
                + " " + item.getName() + " " + item.getSize());
    } else {
        renderXmlResponse(request, response, XML_ERROR_ITEM_NOT_FOUND);
        logger.info("UPLOAD-SERVLET (" + request.getSession().getId() + ") removeUploadedFile: " + parameter
                + " unable to delete file because it isn't in session.");
    }

    return item;
}