• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Values in a text field

 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to set the value of a text field within a form to the value stored in a variable. The only way I know to set the value for a text field inside a form is to set it using value= inside the HTML tag which will only print out what follows as a literal. Is there any way to do what I'm trying to do or am I barking up the wrong tree?
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to print the whole html form from inside the servlet.
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is what I have done with an empty text field. When text is typed in, it is sent to the servlet when submit is clicked. My problem is finding a way to place the text back inside the text field after it has been reversed. Since the reversed text has to be placed in the same form to be returned back to normal, there must be someway to place it in the text field without using value=! This is where I'm getting stuck.
 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that there is only one solution: send back the total html-page with changed textfield (value=...). Because the HTML-page is already sent to the client and you have no connection to that machine anymore. The connection to your server is only by 'submit' (and receive a correct HMTL page).
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have the original html page. You type in the text. You go to the servlet. The servlet creates a new html page including the test you typed in. voila! Text in the textbox.
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But it's not working! I can retrieve the text from the text field and reverse it. No problem. When I try to input the reversed text into the text field using value=phrase.reverse() all I get in the text field is phrase.reverse(). I am missing someting here, like how to place the reversed text in the html form.
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you are putting all of that within a String literal. You need to concat the returned value from reverse() to the string you are printing for your HTML page.
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay let me explain my frustration before I trash my computer!
The only way I know of (or can find by looking at examples) to set the text inside of a text field within a form is by using value=. I have no string literal to put after value= since I don't know what the user will type into the blank text field in the form. How do I get the String that I have retrieved from the first form and reversed back into the text field???
I can send the reversed string to out.println, but it won't appear inside the text field. If I create another html document with another text filed inside a form, I can't set the text without having a literal to put after value=. I am not going to be able to sleep tonight without getting quite drunk!
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Carol Murphy:
Okay let me explain my frustration before I trash my computer!
The only way I know of (or can find by looking at examples) to set the text inside of a text field within a form is by using value=.

Yes. That is correct.

I have no string literal to put after value= since I don't know what the user will type into the blank text field in the form.


Retrieve the String from the first form the same way you did in Reverse. This is the string (reversed) that you use as your String literal for your value= in the html form that your servlet will create.

How do I get the String that I have retrieved from the first form and reversed back into the text field???

Can you create a new html form containing a text field and a submit button from the servlet?

I can send the reversed string to out.println, but it won't appear inside the text field.

True.

If I create another html document with another text filed inside a form, I can't set the text without having a literal to put after value=.

Set the text to the String literal you got from the user (reversed). The servlet should create another html document with the value=theStringYouGotFromTheUserReversed
 
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey carol, how's the hangover?
i had a couple sleepless nights over this problem as well... so you are generating the initial html page from the servlet, right? what is the initial value in the textbox? it is blank ( "" ), right?
now you have some input to place in the textbox, right? you are using the same servlet to generate the new html page, but the textbox value isn't ( "" ), is it?
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're not using a String that contains "...value=...", then how are you generating your webpage from the servlet??? Where are you putting all of the html code? You said that you are actually seeing phrase.reverse() in the text field. That tells me that instead of attaching the value of the reversed phrase to the html, you have that method call actually in the string (I have to assume you are using strings to generate your webpage from the servlet because frankly I don't know if there is any other way to do it).
One thing I do remember is reverse() doesn't actually return a String value, it just does the work on the calling string and that's that. Could this be part of the problem?
Jason
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reminding me, Jason. You don't start with an html page for the Reverse2 assignment as you do for the Reverse assignment, but strictly print the html from the servlet.

So, Carol, ignore my previous post. Print the html page from the servlet with the value=emptyString.

When the user presses the "submit" button, print part of the html page from the servlet, print the new value you got from the user reversed, print the rest of the html.

[This message has been edited by Marilyn deQueiroz (edited November 19, 2001).]
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Uncle already! I am now officially begging for help. Here's where I stand:
I have successfully generated a web page from the servlet that contains a text field and a submit button. There is no html file by itself. This charming little web page will allow the user to enter text in the text field and will reverse it. If no text is entered it will prompt the user to type a phrase. This prompt appears inside of the text field right where I want it to be. It all falls apart after that because I cannot get the reversed text to print out inside the text field. I can print it before the text field. I can print it after the text field. Since I can't point value= to a variable, I can't put it inside the text field! Is there a command I can put inside of the action attribute that will post the response to the text field instead of the entire servlet? Perhaps that's the problem, I need to post to the form and not the whole stinkin' page?
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html>< more html stuff >
<form ... value=
out.print( reversedString )
rest of html stuff>
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>Since I can't point value= to a variable, I can't put it inside the text field!
yes you can... when the html is being generated from the servlet, it is just a bunch of code, strings, variables, etc. until it is sent to an html page...
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marilyn, that is what I thought would work, but when I submit a line of text that has been entered into the blank text field, I get out.print(myVariableName) as the text in the text field! This is driving me nuts! (Well, nutsier)
From what I can tell, value= will print whatever I put after it as a literal, therefore I can't access my reversed String!
Any ideas?
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should have other out.print() methods that are printing all the HTML code as either separate Strings, like out.print( "< HTML>..." ); or have a String that holds all that already and just print that variable, like String stuff = "< HTML>....";
out.print( stuff );

Groovy, thanks Marilyn

[This message has been edited by jason adam (edited November 20, 2001).]
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jason adam:
... like out.print( "<HTML>..." ); or have a String that holds all that already and just print that variable, like String stuff = "< HTML>....";
out.print( stuff );
Ignore the extra single quotes, I can't remember how to put in html code in these posts


You can use a space after the opening < so UBB knows that it should not interpret the stuff after it as html. Or you can use &lt; for the opening < . Personally, I think using the space is easier.

[This message has been edited by Marilyn deQueiroz (edited November 20, 2001).]
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all of your help and suggestions, but nothing has helped me fix the problem yet. I still get my variable name printed out in the text field instead of the reversed string the variable name represents. I give up. I'm going to my parent's house for Thanksgiving. Happy Thanksgiving everyone!
 
reply
    Bookmark Topic Watch Topic
  • New Topic