• Post Reply Bookmark Topic Watch Topic
  • New Topic

can't get the local variable value in the value attribute of <input> tag

 
Gautam Joshi
Greenhorn
Posts: 18
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here, I have just tried out to take a value from the database and storing it into local variable then I want to have that value in the value attribute of <input> tag but somehow, I can't get it..

Here, below is my code..



I'll appreciate your answers...need help..!! Thanks in advance..!!
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a good practice to use Java code in JSP.
Move the Java code to a servlet, set required attributes, forward to JSP, and access attributes from JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact, the way you have that code in the JSP ensures (not maybe, not might, but guarantees) that your code will break badly when more than one person tries to use your site at the same time.

Learn proper practices now. Move all the Java code out of the JSP and into Java classes where it belongs.

Your servlet controller should be in charge of getting the data from the database (preferably delegating to the model layer), and send the value to the JSP as a scoped variable where the JSTL and EL can make it the value of your input element.

Please read
  • The Secret Life of JSPs
  • The Front Man
  • . The first to make sure that you understand what JSP is all about, and the second to understand why your current structure is so off.
     
    SaurabhRc Jain
    Greenhorn
    Posts: 12
    Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have never used $ to access variables on jsp.
    Try something like <%= unm%>.

    Anyways, please don't ignore the advise in above two posts. Refactor your code before shipping out.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65524
    105
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    SaurabhRc Jain wrote:I have never used $ to access variables on jsp.
    Try something like <%= unm%>.

    No. Do not! This is bad advice.

    The JSTL and EL were introduced with JSP 2 twelve years ago. Twelve! No one should be using old-fashioned scriptlets in JSP code anymore. No one.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!