473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 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 :-
Expand|Select|Wrap|Line Numbers
  1. <%@ page language="Java" %>  
  2. <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%><%@ page contentType="text/html;charset=windows-1252"%>
  3. <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  4.  
  5. <html:form action ="taskAction.do">
  6.   <head>
  7.     <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  8.     <title>untitled</title>
  9.   </head>
  10.   <body>
  11.     <form >
  12.       <P> </P>
  13.       <BLOCKQUOTE>
  14.         <BLOCKQUOTE>
  15.           <BLOCKQUOTE>
  16.             <BLOCKQUOTE>
  17.               <P>
  18.                 <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>
  19.                   <SPAN style="background-color:rgb(255,255,255); background-color:rgb(204,204,204);">TASK MANAGER</SPAN>
  20.                 </h1></U></STRONG> </FONT><SPAN style="background-color:rgb(204,255,255); background-color:rgb(204,204,255);"><FONT color="#003300"> </FONT></SPAN> </SPAN></SPAN></P>
  21.             </BLOCKQUOTE>
  22.           </BLOCKQUOTE>
  23.         </BLOCKQUOTE>
  24.       </BLOCKQUOTE>
  25.       <P>
  26.         <SPAN style="background-color:rgb(204,255,255); background-color:rgb(204,204,255);"><FONT color="#003300">          Task Id            
  27.             <html:text property="taskid"/>
  28.           </FONT>
  29.         </SPAN>
  30.       </P>
  31.       <P>
  32.         <SPAN style="background-color:rgb(204,255,255); background-color:rgb(204,204,255);"><FONT color="#003300">          Task Name      
  33.             <html:text property="taskname"/>
  34.           </FONT>
  35.         </SPAN>
  36.       </P>
  37.       <P>
  38.         <SPAN style="background-color:rgb(204,255,255); background-color:rgb(204,204,255);"><FONT color="#003300">           Date               
  39.             <html:text property="dateOfBirth"/>
  40.           </FONT>
  41.         </SPAN>
  42.       </P>
  43.       <P>                                                                      
  44.       </P>
  45.       <P>                                                                                            
  46.       <input type="submit" value="Submit"/></P>
  47.     </form>
  48.   </body>
  49. </html:form>
  50.  

taskAction.java :-
Expand|Select|Wrap|Line Numbers
  1.  
  2. //import TaskBO;
  3. import org.apache.struts.action.Action;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.*;
  7.  
  8.  
  9.  
  10. public class taskAction extends Action 
  11. {
  12.  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
  13.                               HttpServletResponse response) 
  14.   {
  15.     ActionForward forward;
  16.     taskform tForm = (taskform) form; 
  17.     Taskdata taskdata = populateTaskdata(tForm);
  18.     TaskBO taskBO = new TaskBO();
  19.     if (taskBO.createtask(taskdata)) 
  20.     {
  21.       forward = mapping.findForward("success");
  22.     }
  23.     else 
  24.     {
  25.       forward = mapping.findForward("failure");
  26.     }
  27.     return forward;
  28.  
  29.   }
  30.     private Taskdata populateTaskdata(taskform form) 
  31.   {
  32.     Taskdata td = new Taskdata();
  33.     td.setTaskid(form.getTaskid());
  34.      td.setTaskname(form.getTaskname());
  35.       td.setDateOfBirth(form.getDateOfBirth());
  36.  
  37.     return td;
  38.   }
  39. }
  40.  
taskform.java :-
Expand|Select|Wrap|Line Numbers
  1.  
  2. import org.apache.struts.action.ActionForm;
  3.  
  4. public class taskform extends ActionForm 
  5. {
  6.  
  7.   private int taskid;
  8.   private String taskname;
  9.   private String dateOfBirth;
  10.   private String update;
  11.   private String delete;
  12.  
  13.   public taskform()
  14.   {
  15.     taskid = 0;
  16.     taskname = "";
  17.     dateOfBirth = "";
  18.   }
  19.  
  20.  
  21.  
  22.   public void setTaskid(int taskid)
  23.   {
  24.     this.taskid = taskid;
  25.   }
  26.   public int getTaskid()
  27.   {
  28.     return taskid;
  29.   }
  30.  
  31.  
  32.   public void setTaskname(String taskname)
  33.   {
  34.     this.taskname = taskname;
  35.   }
  36.  
  37.     public String getTaskname()
  38.   {
  39.     return taskname;
  40.   }
  41.  
  42.   public void setDateOfBirth(String dateOfBirth)
  43.   {
  44.     this.dateOfBirth = dateOfBirth;
  45.   }
  46.  
  47.  
  48.   public String getDateOfBirth()
  49.   {
  50.     return dateOfBirth;
  51.   }
  52.  
  53.  
  54.   public void setUpdate(String update)
  55.   {
  56.     this.update = update;
  57.   }
  58.  
  59.  
  60.   public String getUpdate()
  61.   {
  62.     return update;
  63.   }
  64.  
  65.  
  66.   public void setDelete(String delete)
  67.   {
  68.     this.delete = delete;
  69.   }
  70.  
  71.  
  72.   public String getDelete()
  73.   {
  74.     return delete;
  75.   }
  76. }
  77.  
Mar 25 '11 #1

✓ answered by Antony Nadan

Hi,
In C# we have a Random class. This class has a member fucntion [I]next()[/i], this will provide a random int data which is unique..


Random ranobj= new Random();
taskid=ranobj.next();

1 6671
Hi,
In C# we have a Random class. This class has a member fucntion [I]next()[/i], this will provide a random int data which is unique..


Random ranobj= new Random();
taskid=ranobj.next();
Mar 29 '11 #2

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

Similar topics

6
by: Paul Robinson | last post by:
I am developing a website in ASP that connects to a Sybase database. However, when I try to open a connection to the database the page will not load. The script does not timeout, nor the...
1
by: Jon | last post by:
I have a bunch of uplevel browser functionality on some pages and need to do something to prevent downlevel browsers from trying to load such pages. These pages would require IE 5 or newer in order...
3
by: vaidas gudas | last post by:
How to make in ASP.NET with VB.NET page, how show preview html page for print in pdf format
3
by: Shimon Sim | last post by:
Hi Is it possible to make sure that the page doesn't show in browser history and won't effect Back button. The problem is that every postback shows as another entry for "Back" button and user...
0
by: Torben Laursen | last post by:
I would like to be able to extract a page from my helpfile and show it in the interface so it is part of the interface and not a popup. Using helpprovider I can get any page to popup but I would...
6
by: karen987 | last post by:
I have a webpage called "topicview.asp" on a news website with ASP pages, it's a simple news publishing software. You add the news from the Admin section and all the details are stored in a...
2
radcaesar
by: radcaesar | last post by:
Hi All, My Clients (C1 and C2) sharing a same application for their business. Now C2 only wants to change the UI of the ASP Pages. Now, If C1 enters, it should show the old ASP Page and...
6
by: ~john | last post by:
I have binary files stored in a SQL Server table that I want the user to be able to download from an aspx webpage. The files are displayed on the form as "LinkButtons". When the link is clicked the...
4
by: Bob Bedford | last post by:
Hi all, I've a site on a hosting that has a protected directory for statistics. The only way to give access to those stats is either give access to everybody or give the customer the admin...
3
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.