#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    1
    Rep Power
    0
    How do I get variables from a form. I read devshed's article but now I am trying to go beyond what they have done and find out how I can get info from a form. Can someone give me a quick explanation or lead me to a place where I could learn how?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Colorado
    Posts
    46
    Rep Power
    14

    Post


    In order to get variables from your HTML form in your servlet you need to access the HTTPRequest object in your doGet or doPost method. I am assuming that you have some code like this:

    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{...}

    In order to get the values that were entered into the form you need to use code like this in your doGet or doPost method:

    String phone = req.getParameter("phoneNumber");

    You will probably have different parameters, but you will just need to enter their names where I have used "phoneNumber". The name you pass to the getParameter() method needs to be the name you gave the field in your HTML form.

    A good tutorial can be found at:

    http://developer.java.sun.com/develo...roduction.html

    I hope that helps.
    - MW

IMN logo majestic logo threadwatch logo seochat tools logo