OK, this question probably has a really obvious answer, but I'm a beginner, so bear with me. I need to make my servlet perform a calculation on values obtained from an html input form. I import the values from the form as a string using, e.g.: String Value = req.getParameter("Value"); However, I cannot then perform any calculations on it, since it is a string, not an integer, for example, nor can I find a way to convert it to an integer. Can anyone help? Quickly would be real good. Thanks, James
Couldn't you just use Integer.parseInt(String) or Integer.getInteger(String)? Let me know if that helps. [This message has been edited by Sean Casey (edited July 09, 2001).]
That looks like the right kind of thing, but I can't get it to work. When I said beginner, I really mean BEGINNER. Below is the code I'm trying to adapt. What I'd like to do is to make "value" (this is the name of the field from the html form) an integer, and then multiply it by 2 or another variable (for example) and display this in the HTML output. Any chance you could enter it into the code below? That would be excellent. Sorry to be so useless { res.setContentType("text/html"); String User = req.getParameter("Value");
Sean gave the answer. If I were a Java instructor (which I am not), I would ask you how come you're already into coding Java Servlets (which is like Java 201) without a mastery of the very basics of Java 101: static int parseInt(String s) throws NumberFormatException BTW, Don't forget to handle the Exception
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.