How to Autogenerate of ID from database and show on JSP page?

How to Autogenerate of ID from database and show on JSP page?

problem in web application : I have a database names tasks in SQL server 2005 having tasks id as primay key, I am using JSP and struts for database connectivity,Now I can update my database but i want to autogenerate tasks id in numbers(ie increasin 1 in the previously stored tsk id) on JSP page when I click on CreateTask.jsp page.How can i do so?My project storing user entered task id,task name ,date etc properly in the database,but what and how should i make it (in taskAction.java) that it auto generate tasksid in jp page when i click on Create_task.jsp and other data user can enter himself.I am using Jdeveloper.Codes: create.jsp :-

<%@ page language="Java" %>  
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%><%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<html:form action ="taskAction.do">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
  </head>
  <body>
    <form >
      <P>&nbsp;</P>
      <BLOCKQUOTE>
        <BLOCKQUOTE>
          <BLOCKQUOTE>
            <BLOCKQUOTE>
              <P>
                <SPAN style="background-color:rgb(204,204,204); background-color:rgb(204,204,204);"><SPAN style="background-color:rgb(255,255,255);"><FONT color="#006666"><STRONG><U><h1>
                  <SPAN style="background-color:rgb(255,255,255); background-color:rgb(204,204,204);">TASK MANAGER</SPAN>
                </h1></U></STRONG>&nbsp;</FONT><SPAN style="background-color:rgb(204,255,255); background-color:rgb(204,204,255);"><FONT color="#003300">&nbsp;</FONT></SPAN> </SPAN></SPAN></P>
            </BLOCKQUOTE>
          </BLOCKQUOTE>
        </BLOCKQUOTE>
      </BLOCKQUOTE>
      <P>
        <SPAN style="background-color:rgb(204,255,255); background-color:rgb(204,204,255);"><FONT color="#003300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Task Id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <html:text property="taskid"/>
          </FONT>
        </SPAN>
      </P>
      <P>
        <SPAN style="background-color:rgb(204,255,255); background-color:rgb(204,204,255);"><FONT color="#003300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Task Name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <html:text property="taskname"/>
          </FONT>
        </SPAN>
      </P>
      <P>
        <SPAN style="background-color:rgb(204,255,255); background-color:rgb(204,204,255);"><FONT color="#003300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <html:text property="dateOfBirth"/>
          </FONT>
        </SPAN>
      </P>
      <P> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      </P>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="submit" value="Submit"/></P>
    </form>
  </body>
</html:form>

taskAction.java :-

//import TaskBO;
import org.apache.struts.action.Action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;



public class taskAction extends Action 
{
 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) 
  {
    ActionForward forward;
    taskform tForm = (taskform) form; 
    Taskdata taskdata = populateTaskdata(tForm);
    TaskBO taskBO = new TaskBO();
    if (taskBO.createtask(taskdata)) 
    {
      forward = mapping.findForward("success");
    }
    else 
    {
      forward = mapping.findForward("failure");
    }
    return forward;

  }
    private Taskdata populateTaskdata(taskform form) 
  {
    Taskdata td = new Taskdata();
    td.setTaskid(form.getTaskid());
     td.setTaskname(form.getTaskname());
      td.setDateOfBirth(form.getDateOfBirth());

    return td;
  }
}

taskform.java :-

import org.apache.struts.action.ActionForm;

public class taskform extends ActionForm 
{

  private int taskid;
  private String taskname;
  private String dateOfBirth;
  private String update;
  private String delete;

  public taskform()
  {
    taskid = 0;
    taskname = "";
    dateOfBirth = "";
  }



  public void setTaskid(int taskid)
  {
    this.taskid = taskid;
  }
  public int getTaskid()
  {
    return taskid;
  }


  public void setTaskname(String taskname)
  {
    this.taskname = taskname;
  }

    public String getTaskname()
  {
    return taskname;
  }

  public void setDateOfBirth(String dateOfBirth)
  {
    this.dateOfBirth = dateOfBirth;
  }


  public String getDateOfBirth()
  {
    return dateOfBirth;
  }


  public void setUpdate(String update)
  {
    this.update = update;
  }


  public String getUpdate()
  {
    return update;
  }


  public void setDelete(String delete)
  {
    this.delete = delete;
  }


  public String getDelete()
  {
    return delete;
  }
}
View Answers









Related Tutorials/Questions & Answers:
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?
Advertisements
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?
How to show data from database in textbox in jsp
how to show effect (visual) on jsp page using value from database
how to retrive data grom database in jsp pages.
How to show database values into graph using jsp?
How to show database values into graph using jsp?
how to retrieve text and images from mysql database and show on html page using jsp servlet
By dropdownlist retrive data from database and show in textbox in jsp.
How to access the database from JSP?
how to retrieve the id value itself from the access database to drop down listbox in jsp
how to show image as a link which path coming from database
how to display data from database in jsp
How to retrieve image from mysql database in JSP?
How to retrieve blob image from database in JSP?
How to store and retrieve image from database in JSP?
retrieving data from database to the textbox depending upon the id in jsp
connect to the database from JSP
how to show data in database ?
how to show value and percentage in piechart sections from database using jfreechart
how to retrieve images from database to jsp?
Loading a jsp page (with record from database) from another jsp page
how to get data from database into dropdownlist in jsp
Get values from JSP pages - JSP-Servlet
Use of Select Box to show the data from database
how to display data from jsp file into database
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp
how to retrieve image from mysql database using java and show it in HTML img tag ?
How to retrieve image from database using jsp and servlet?
display date to jsp from database
How to display image in jsp from database using Servlet?
line chart from database in jsp
How save,get picture from database in my jsp page?
Delete a row from database by id
how to display values from database into table using jsp
jsp pages for dispatchaction for adding user to database
Update Database from jsp
how to display image and text in single jsp page from the mysql database
how to generate reports from oracle database using jsp and ajax code
How we delete a data of database from front end jsp page
How to fetch entries/values from database to a jsp page one by one?
How to Retrieve data from database in jsp
How to get the data from the database using Servlet or JSP program
how to read values from excel sheet and compare with database using jsp
How to get data from Oracle database using JSP
How to show next question from database on the click of next button..(Struts & Hibernate)
How to show next question from database on the click of next button..(Struts & Hibernate)

Ads