File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how to make form ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to make form ?" Watch "how to make form ?" New topic
Author

how to make form ?

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, i creating a form which can get data from DB, and this form mostly have textfield and also how to make it savable at the same time ? i actually don't know how to display data into textfield..thank you
evan theon
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
since you're posting this topic on JSP category of the forum, i assume you are trying to do what you were asking by JSP. well, first of all you must build a connection to your DBMS, which you haven't mention yet in your posting.
then create a database query to choose the data you want, since you are trying to retrieve data from database you should use a SELECT query to a table or a view. the query result, in JSP, can be stored in a java class ResultSet, from that class you can put the retrieved data into a textfield, even into a combo box, or simply display it on your web site's screen.
So i need to know what kind of DBMS do you use? SQL Server, MySQL, PostgreSQL, or else? by then we can start the explanation all over again, OK?
regards
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, evan , thanks for reply , i understand the basic concept of jsp which get and set the data from or to DB, the thing i confuse is , let say i have
many fields something as below



as show above, i use javabeans to retrieve data and pass it into textfield, my problem is if i want to make the form which is editable and then allow user to save the data into DB after click the modify button , how to i do that ?
Eugene Lucash
Ranch Hand

Joined: Feb 19, 2005
Posts: 77
Introducing PSEUDO code to give you insight
This is not real code but it shows main idea



SELECT Name, Id FROM Users WHERE Id=SomeId
ResultSet rs = use jdbc ^^^^
MyUserBean mub = MyUserBean();
mub.setId(rs.getInt("Id"));
mub.setName(rs.getString("Name"));
%>
<form action="/editUser.jsp" method="post">
<input type="text" name="name" value="<%=mub.getName()%>">
<input type="text" name="id" value="<%=mub.getId()%>">
<input type="submit">
</form>

----->>
SUBMIT
-->>>
<%
String id = request.getParameter("id");
String name = request.getParameter("name");

JDBC...
"UPDATE Users SET id= " + id
+ ", name='" + name + "' WHERE id = " + id;
Execute it
%>
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
would it be a problem since i already put the value into textfield , and then modify and save it again ? as we see



would it save back the qb.getCustsn() value rather than modified value in textfield?
evan theon
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
the request.getParameter will technically read the last value of the parameter, in this case, the username textfield. so when you update the username field in the db, it will automatically updaetd, and when the second time visit that page the value will have changed
remember that request.getParameter is triggered when you submitted a form, so the changes will occur after you press the ,let's say, 'Save' button
try it n have fun!
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
thanks you for reply ...have a nice day
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to make form ?
 
Similar Threads
Textfield border disappears after validation
How to do a preview page for submitted form
textfield and UTF-8 format
ajax and struts2
j2me - RMS & appending textfield