• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

capturing variable in "value" field of the form

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this code will provide default text in the textfield as "enter query"

If I want this value to be provided by java variable input_text, where input_text has value of "enter query"




In the first instance, default value for the input text field will become


while in second instance value=enter query , will this be valid ?

I tried it both ways and in the text field, I got "null".

How to capture value dynamically ?

thanks
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your first step should be to find out which of those things generates the HTML you want. (Use "View Page Source" in your browser.) If none of them do, then make the appropriate changes or ask a question here in which you post the desired HTML as well as your proposed JSP code.
 
hexin orsen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you use like this


you most make sure that input_text is not null,and its instance exist pageScope requestScope...otherwise that show null.

eg:



after save input_text in requestScope ,you can use it in jsp page like
one way:

anthoer way using el:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hexin orsen wrote:you most make sure that input_text is not null,and its instance exist pageScope requestScope

Not correct. When using old-fashioned scriptlet expressions, the variable must be a scripting variable, not a scoped variable.

after save input_text in requestScope ,you can use it in jsp page like

Again, not correct. Scoped variables are accessed via the modern EL, not out-moded scriptlets.

anthoer way using el:

When using scoped variables -- which this user is most likely not doing -- the EL must be used (or complicated scriptlet crap that shouldn't be used).
 
hexin orsen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first thanks Bear criticism,i did not communicate their ideas clearly and had several mistakes.

hexin orsen wrote:
you most make sure that input_text is not null,and its instance exist pageScope requestScope

Not correct. When using old-fashioned scriptlet expressions, the variable must be a scripting variable, not a scoped variable.


i say that input_text is servlet to jspcode.but it can be initialized in jsp



if you do this ,input_text will aotu-save in current pageSope;

after save input_text in requestScope ,you can use it in jsp page like

Again, not correct. Scoped variables are accessed via the modern EL, not out-moded scriptlets.


el get parameter's values in pageScope or requestScope ..... even now , you can initialize :input_text = null;
that is correct.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hexin orsen wrote:i say that input_text is servlet to jspcode.but it can be initialized in jsp

Scriptlet variables have nothing to do with servlets and are not carried from servlets to JSP. You are confusing scoped variables and scripting variables.

if you do this ,input_text will aotu-save in current pageSope;

Again, incorrect. Nothing "auto-saves" to page scope or anywhere else.

el get parameter's values in pageScope or requestScope ..... even now , you can initialize :input_text = null;
that is correct.

I'm not sure what you are trying to say here, but the poster is not using the EL, but scriptlet expressions (even though their use is discouraged these days).
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nirjari patel wrote:

How to capture value dynamically ?



What do you mean by dynamic here ? if you store the value "enter query" in JSP scriplet variable and use it in same JSP , is that dynamic ? if the text value is generated out of some logic , then it can be said dynamic and this logic is more appropriate to be coded inside servlet or helper class and exposed as scoped variable to be used in JSP.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic