• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting an Integer from a form

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I want to get a integer from a hidden form field to a new page.Iam getting error when i use
int
int j=Integer.ParseInt(request.getParamter("ProductID")); or
int j=request.getParamter("ProductID");
i even tried getInt also.
Wat is the right syntax for this case?
The same method works when i get a float.

Error i got
D:\Chari\Tomcat\work\Standalone\localhost\ShoppingCart\jsp\ShoppingCart_jsp.java:51: cannot resolve symbol
symbol : method getParamter (java.lang.String)
location: interface javax.servlet.http.HttpServletRequest
int j=request.getParamter("ProductID");
Waiting for your reply
Chari
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's
parseInt
and
getParameter
these things can easily been seen looking at the API !
 
Lakshmi Chari
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the answer. :-)
Now i have another doubt.
Iam pulling the details of the product from a database and from there iam sending it another page.
Wat i did
is stored the contents in a string and have transferred it using hidden form fields.Since the product name is having spaces,iam unable to get the entire name of the product.how can i do it?
Sorce Code:
while(rs.next())
{
%>
<%
int i=rs.getInt("ProductID");
String j=i+"";
String x=rs.getString("WineName");
float y=rs.getFloat("Price");
%>
<TR>
<TD><%=x%></td>
<td><%=y%></td>
<td>
<form name=CartItem method="POST" ACTION="ShoppingCart.jsp" TARGET="tempwindow">
<select name=CartItem>
<%
for(int k=0;k<9;k++)
{
%>
<option name=<%=k %>><%=k %></option>
<% } %>

</select>
</td>
<input type=hidden name="WineName" value=<%=x%>>
<input type=hidden name="Price" value=<%=y%>>
<input type=hidden size="40" name="ProductID" value=<%=j%>>
<td><input type="submit" value="Buy"></td>
</form>
Pls help me
Regards
Chari
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A little bit of care on your part will save you lots of time and aggravation (like making sure you have typed method names correctly). In this case, have you looked at the HTML code that is being sent to the browser to try and determine why the spaces are causing problems?
If you did you would find that your code:
<input type=hidden name="WineName" value=<%=x%>>
doesn't fit the bill because you forgot to quote the value attribute.
<input type=hidden name="WineName" value="<%=x%>">
will eliminate any problems you might have with spaces and other special characters.
bear
[ November 13, 2003: Message edited by: Bear Bibeault ]
 
Lakshmi Chari
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the info.
Sorry Iam bit new to JSP.
Thnks again for the help
Cheers
Chari
reply
    Bookmark Topic Watch Topic
  • New Topic