aspose file tools
The moose likes Servlets and the fly likes String to variable - urgent! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "String to variable - urgent!" Watch "String to variable - urgent!" New topic
Author

String to variable - urgent!

James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
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
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
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).]
Peter Thomas
Greenhorn

Joined: Jul 09, 2001
Posts: 2
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");

ServletOutputStream out = res.getOutputStream();
out.println("<html>");
out.println("<head><title>Hello User!</title></head>");
out.println("<body>");
System.out.println("Value");
out.println("</body></html>");
}
James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
Oops, went on to my friends user there. Confusing. Sorry
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3219
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.
 
subject: String to variable - urgent!
 
Similar Threads
How to Validate the Integers doesnot allow the string values using java
how to get value from popup window
accessing int value from previous page
Difference between Properties class and HashTable,HashMap
how to use parseInt()