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

Ads

 
 
 

Share on Google+Share on Google+

gurpreet singh
How to Autogenerate of ID from database and show on JSP page?
0 Answer(s)      6 years and 2 months ago
Posted in : JDBC

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 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;
  }
}
Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
Advertisements
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads