473,597 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Integer question involving JSP/HTML FORM

108 New Member
Greetings,

Within my jsp I have HTML code (see below) which accepts input, one of these fields sequence unlike the others is an Integer.

Expand|Select|Wrap|Line Numbers
  1. <FORM ACTION="wk465682AddFAQ.jsp" METHOD="POST">
  2.   Id: <INPUT TYPE=TEXT NAME=Id><BR><BR>
  3.   Category: <INPUT TYPE=TEXT NAME=category><BR><BR>
  4.   Question<BR><TEXTAREA NAME=question COLS=100 ROWS=2></TEXTAREA><BR><BR>   
  5.   Answer<BR><TEXTAREA NAME=answer COLS=100 ROWS=4></TEXTAREA><BR><BR> 
  6.   Sequence: <INPUT TYPE="int" NAME=sequence><BR><BR>       
  7.   <INPUT TYPE=Submit VALUE="Add to Database">
  8. </FORM>
These values are then retrieved in the same jsp file using the code below and inserted into the table (sequence field in a Number in MS acess):-

Expand|Select|Wrap|Line Numbers
  1. Enumeration parameters = request.getParameterNames();
  2.  
  3.  if(parameters.hasMoreElements()) {
  4.     String IdParam  = request.getParameter("Id");
  5.     String categoryParam  = request.getParameter("category");
  6.     String questionParam = request.getParameter("question");    
  7.     String answerParam = request.getParameter("answer");    
  8.     Integer sequenceParam = request.getParameter("sequence");
  9.     statement.executeUpdate("INSERT INTO FAQ (\"Id\",\"category\", \"question\", \"answer\", \"sequence\", \"UserId\", \"created\") VALUES ('"+IdParam+"','"+categoryParam+"','"+questionParam+"','"+answerParam+"', '"+sequence+"', '"+ session.getAttribute("theName")+"', '"+dateString+"')   ");
  10.   }
  11. ResultSet columns = statement.executeQuery("SELECT * FROM FAQ");
  12. while(columns.next()) {
  13.     String Id  = columns.getString("Id");
  14.     String category  = columns.getString("category");
  15.     String question  = columns.getString("question");    
  16.     String answer = columns.getString("answer");
  17.     String userId  = columns.getString("userId");    
  18.     String created = columns.getString("created");
  19.     Integer sequence = columns.getInt("sequence");
  20.  
The jsp falls over with error regarding sequence as It cant convert between String to Integer and Int to Integer.

I've been looking at examples, but obviously I arent declaring the sequence value as an Integer properly.

Any advice would be appreciated
Cheers Rob
Mar 13 '08 #1
2 3864
Dököll
2,364 Recognized Expert Top Contributor
You should probably use an Auto-Generated ID in your back-end, if which case you would not need :
Expand|Select|Wrap|Line Numbers
  1.  
  2. String Id  = columns.getString("Id"); 
  3.  
  4.  
In which case, it should really be:

Expand|Select|Wrap|Line Numbers
  1.  
  2. int Id  = columns.getInt("Id"); 
  3.  
  4.  
but again, only if necessary would you need to insert id values in code. maintain your back-end to accept an auto number when data are added, then you can retrieve using getInt...
Dec 13 '08 #2
JosAH
11,448 Recognized Expert MVP
@robtyketto
Here are the valid type specifications for an input field:

HTML input type Attribute

As you can see there is no such thing as an 'int' type; also note that this has nothing to do with auto generated values; forget about that; that reply was totally incorrect.

kind regards,

Jos
Dec 13 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

73
7959
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only LISP has rationals as far as I can tell. Because CL supports keyword arguments, it has a wider range...
17
3576
by: Robert Baer | last post by:
I used Google and found some references for integer in Java. But "int" not only does not work, it also prevents reading X and Y coordinates of the mouse. What i would like to do: 1) Get X and Y mouse coordinates into a variable that i can do real math on. So far, i can do math on the values "read" and that result goes into a "variable" that is useful *only* for display. If i try "int" in that math, the values are then zero for everything...
458
21035
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers simply aren't smart enough to understand C++? This is not merely a whimsical hypothesis. Given my experience with Java programmers --- the code they write and the conversations they have --- Occam's Razor points to this explanation. For example,...
2
6943
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
15
2780
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interfaceâ€. In a functional language, a function can be specified by its name and parameter specs. For example: f(3) f(3, )
7
2207
by: judge82 | last post by:
please I am learning how to use servlet. here is my code package TestWebApp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class RegLoginServlet extends HttpServlet {
1
3699
by: gypsyman58 | last post by:
First I need to create 2 classes. The first will contain an ID number and an array of 5 course titles. I also have to create a get and a set method for populating the ID. I also must create a method to get a course. It does this by taking an integer and returning the course to that position (0 through 4). Then I must create a set method that sets the value of one of the courses by taking two arguements a name and an integer and returning the...
49
2870
by: aarklon | last post by:
Hi all, See:- http://www.cs.princeton.edu/introcs/faq/c2java.html for C vs Java in number crunching http://husnusensoy.blogspot.com/2006/06/c-vs-java-in-number-crunching.html
0
7969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.