Getting multiple parameters in a servlet

Discussions

Web tier: servlets, JSP, Web frameworks: Getting multiple parameters in a servlet

  1. Getting multiple parameters in a servlet (3 messages)

    I have a JSP page with 5 Submit buttons
    I have another 2 JSP with another 2 submit Buttons

    On GET action i invoke a ControlServlet

    In the control servlet i need to identify which button was pressed.

    How do i do it?

    1) I tried naming all buttons as same and using getParameter("buttonname"). It returns null.

    2) I tried getParameterValues("button").
       It gives NullPointerException.

    Can anyone give me ideas on how to do this or else i will land up with long code or using many servlets.

    Thanks in advance.
  2. use a hidden form field!

    e.g.:
    <input type="hidden" name="activeButton" value="1">

    <button type="submit" value="Click here 1">

    <button type="button" name="button2" value="Click here 2" onclick="document.form.activeButton='2'; document.form.submit();">

    <button type="button" name="button3" value="Click here 3" onclick="document.form.activeButton='3'; document.form.submit();">

    <button type="button" name="button4" value="Click here 4" onclick="document.form.activeButton='4'; document.form.submit();">

    <button type="button" name="button5" value="Click here 5" onclick="document.form.activeButton='5'; document.form.submit();">

    Should work with IE and NS.

    Mathias Bogaert
  3. OOPS some errors damn

    Here is the new version:
    <form name="data" action="servlet/someservlet" method="get">
    <input type="hidden" name="activeButton" value="1">
    <input type="submit" value="Click here 1">
    <input type="button" name="button2" value="Click here 2" onclick="document.data.activeButton.value='2'; document.data.submit();">
    <input type="button" name="button3" value="Click here 3" onclick="document.data.activeButton.value='3'; document.data.submit();">
    <input type="button" name="button4" value="Click here 4" onclick="document.data.activeButton.value='4'; document.data.submit();">
    <input type="button" name="button5" value="Click here 5" onclick="document.data.activeButton.value='5'; document.data.submit();">
    </form>

    :))
  4. whats the error???