Assign variable to the value in HTML

32,643

Solution 1

Your question is not very clear. I'll assume the variable is declared inside a servlet, because it's bad practice to use Java in a JSP. To be able to share a variable between a Servlet whic forwards to a JSP, you need to set this variable into a request attribute:

String registration = "10-120";
request.setAttribute("registration", registration);

And then in the JSP, you can get the value of the "registration" attribute using the JSP EL:

<input type="text" name="registrationUpdate" value="${registration}" maxlength="50" />

You should read the Java EE tutorial: http://docs.oracle.com/javaee/5/tutorial/doc/bnadp.html

Solution 2

itz very simple

    <% String registration="10-120"; %>
    <input type="text" name="registrationUpdate" value="<%=registration%>" maxlength="50" />

hope this will help you

Share:
32,643
Shahid Ghafoor
Author by

Shahid Ghafoor

Updated on August 29, 2020

Comments

  • Shahid Ghafoor
    Shahid Ghafoor over 3 years
    String registration="10-120";
    <input type="text" name="registrationUpdate" value="Reg#" maxlength="50" /><br>
    

    In the above , value="Reg#" which is hard code. I want to assign variable to the value. i.e. Means value=registration;

    update me!