Removing a Parameter from the HTTPRequest object

Discussions

Web tier: servlets, JSP, Web frameworks: Removing a Parameter from the HTTPRequest object

  1. Removing a Parameter from the HTTPRequest object (4 messages)

    Hi,

    I have a http form which has two name/value pairs (SVCNAME and STRING) which call a servlet. I want to be able to remove the SVCNAME parameter and value from the request object in the servlet, so that only the STRING parameter remains. Any help gratefully appreciated.

    Regards,

    Steve Hill
  2. use this method :

    request.removeAttribute(strAttributename)
  3. Amol,

    I tried the following and received an incompatible type error on compiling:

    req = req.removeAttribute("SVCNAME");

    tp_60000.java:115: incompatible types
    found : void
    required: javax.servlet.http.HttpServletRequest
        req = req.removeAttribute(svcnm[0]);

    Any clue?
  4. Now I'm a little confused....

    If I do :

    Enumeration params = req.getParameterNames();

    I can step thru the parameters and their values.If I do req.getAttributeNames(), I don't see any elements. I can step thru the various parameters but can't see a method of removing a parameter/value pair. Are attributes associated with sessions/cookies?
  5. The reason you get the error message is because the removeAttribute method does not return anything. Its return type is void but you were trying to put the return value in req.
    So just call req.removeAttribute(abc)
    instead of req = req.removeAttribute(abc)

    Regards,
    Sneha