0

This question was asked earlier in 2016 but the guy that asked didn't get the answer. So does anyone know how to get this ID which is already AI but I need it shown automatically in a html form. So I am inserting a new user which still doesn't have ID assigned .

       <h3>Kreirati korisnika</h3>
    <form action="kreiraj_korisnika.jsp">
      <div class="form-group" >
        <label for="id_clan" >ID:</label>
        <input type="text" class="form-control" id="id_clan" name="id_clan">
      </div>

1 Answers1

0

First you have to get the next possible Id. Check this for the instructions:

https://dev.mysql.com/doc/refman/8.0/en/getting-unique-id.html

Then you can work with the data:

The textbox:

<input type="text" class="form-control" id="id_clan" name="id_clan" value="<%= yourId%>"/>

JSP code:

<%! String yourId; %>
<%
  //do some code to receive your data
  yourId="YOUR_ID";
%> 

See here for more info: Assign value to HTML textbox from JSP

or

https://www.quora.com/How-do-I-pass-the-text-entered-into-an-HTML-text-box-to-a-Java-method-if-I-am-using-JSP

G43beli
  • 3,835
  • 4
  • 21
  • 28
  • But that is the problem, I don't know how to receive my data if it hasn't been inserted into database yet ? – Milica Miletic May 07 '18 at 07:48
  • sso you mean you have the data, but it is not already inserted in the database? – G43beli May 07 '18 at 07:51
  • check this: https://stackoverflow.com/questions/12014140/how-to-get-last-inserted-id-into-jdbc-in-jsp and this: https://stackoverflow.com/questions/1405393/finding-the-next-available-id-in-mysql – G43beli May 07 '18 at 07:54
  • No, I am adding a new user to the database through html and I want my Id to generates automatically in the textfield – Milica Miletic May 07 '18 at 07:59
  • 1
    @MilicaMiletic you have to get the last inserted record and then just add 1+ to the received id: see this https://dev.mysql.com/doc/refman/8.0/en/getting-unique-id.html – G43beli May 07 '18 at 08:04
  • I add it to my answer and you can mark it as solution if it helped. Thx – G43beli May 07 '18 at 14:06