I am an extreme newbie when it comes to JSP and I am really stuck. This is my code:

while (rst.next()) {

    	out.println(" <td width='10%'>"+id+"</td>");
     	out.println(" <td width='20%'>"+nme+"</td>");
     	out.println("<td width='10%'>"+twn+"</td>");
      	out.println("<td width='10%'>"+cny+"</td>");
	out.println("<td width='10%'>Edit</td>");
      	out.println("<td width='10%'>Delete</td>");
 out.println(" </tr>");

Where it says "edit" and "delete" I want them to be buttons but I can't seem to create one. I want the edit button to take the strings to another page (for editing) and the delete button to delete that record (will the while thing at the top cause me problems)?


6 Years
Discussion Span
Last Post by javaAddict

Delete everything.
Don't use the above code. (Html in servlets)

Create a class with attributes the id, nme(name ?), twn(town ?), cny(country ?).
Create a class that has a method that does the database operations and returns the data. Probably a list of the above class (id, nme, twn, cny)
Inside a jsp call that one single method to get the data and then use scriplets to display them.
When you click a button you can call a javascript function that submits a form to the page that you want.
Or instead of buttons you can have href links:

for (int i=0;i<arrayOfData.length;i++) {
  //i-th elements that has the data from the database

  String id = arrayOfData[i].getId(); // just an example, arrayOfData being an array of the class you created with the attributes. You call the get methods

  <a href="delete.jsp?id=<%=id%>">Delete</a>


If the above doesn't make much sense then you need to study more about the basics before starting to work with jsps.
The same goes about scriplets. Get a book and learn how to use them in jsps, and don't write code that connects to the database in a jsp. Call a method that gets you the data.

Also take a look at the link at the top of this forum with title:
JSP database connectivity according to Model View Controller (MVC) Model 2
And then leave a positive feedback to the author for his effort in creating such a good tutorial

Edited by javaAddict: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.