aspose file tools*
The moose likes JSP and the fly likes capturing variable in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "capturing variable in "value" field of the form" Watch "capturing variable in "value" field of the form" New topic
Author

capturing variable in "value" field of the form

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 374

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 14, 2009
Posts: 4
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

Joined: Jan 10, 2002
Posts: 61233
    
  66

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).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
hexin orsen
Greenhorn

Joined: Aug 14, 2009
Posts: 4
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

Joined: Jan 10, 2002
Posts: 61233
    
  66

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

Joined: Jan 01, 2009
Posts: 874

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: capturing variable in "value" field of the form