#1
  1. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0

    Another conversion problem....


    I'm trying to get an integer value from request, but i get an error message saying that the method doesn't exist. Neither of these work:
    Code:
    count = request.getInteger("count");
    count = request.getInt("count");
    This is JSP on 1.2.2
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3887
    Try this:
    Code:
    count = Integer.parseInt(request.getParameter("count"));
    ~ishnid
  4. #3
  5. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Here's the exact error message.

    And I have no idea why getInt() isn't working, cause it's in javadocs 1.2.2
    Code:
    Unable to compile class for JSP/opt/netscape/server4/https-web/config/../ClassCache/_jsps/_infosys/_infra/_software/_database/_calendar/_do_del_jsp.java:256: Method getInt(java.lang.String) not found in interface javax.servlet.http.HttpServletRequest.
                                    count = request.getInt("count");
  6. #4
  7. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Thx ishnid, that worked.

    I just wonder why getInt() doesn't work.

    [Edit]
    Peachy, now I'm getting NumberFormatException.

    Anyone know offhand what throws that exception?

    Here's a code snipet:
    Code:
    	try 
    	{
    		Class.forName("oracle.jdbc.driver.OracleDriver");
    		conn = DriverManager.getConnection(db_url,db_user,db_pass);
    		String delete_ids = request.getParameter("del_vals");
    		count = Integer.parseInt(request.getParameter("count"));
    		String[] del_arr = { "" };
    		StringTokenizer tokens = new StringTokenizer(delete_ids, ",");
    
    		out.println(delete_ids + "<br/>");
    		for(int i = 0; i < count; i++)
    		{
    			if(tokens.hasMoreTokens())
    			{
    				del_arr[i] = tokens.nextToken();
    			}
    		}
    Last edited by StevenC; July 14th, 2003 at 09:06 AM.
  8. #5
  9. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3887
    I haven't seen getInt() used with a HttpServletRequest before and can't find it in the APIs. The code I posted is what I always use for this kind of problem.
    ~ishnid
  10. #6
  11. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Ok, thx.
  12. #7
  13. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3887
    As for your NumberFormatException, that can happen with the code I posted if the parameter doesn't look like an integer (i.e. it has letters or symbols or a decimal point).
    ~ishnid
  14. #8
  15. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    If you are taking a request param and trying to make a number out of it, always assume it could be supplied as something other than a valid number. You should catch the numberFormatException and take appropriate steps to fix it (use a default value or notify the user that the value supplied was invalid or something).

    I am curious where you saw that request.getInt was a method? The 1.2.2 javadocs have no J2EE classes in them. Are you sure you were looking at the HttpServletRequest?
  16. #9
  17. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Nemi, I had used getInt somewhere else where I was programming. Not sure where I got it from. Might have the 1.4 docs.

IMN logo majestic logo threadwatch logo seochat tools logo