Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting an Integer from a form  RSS feed

 
Lakshmi Chari
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66198
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks a lot for the info.
Sorry Iam bit new to JSP.
Thnks again for the help
Cheers
Chari
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!