getting values

[nobr]Hi,

I have a question which is related to forms and hope someone and can help me.

I have a form which first asks you if you are male or female then displays a separate form based on selection.

out.println("<form method=\"post\" action=\"");

out.println(this.getClass().getName() +"\">");

out.println("<input type=\"radio\" name=\"sex\" value=\"Female\">");

out.println("Female <br>");

out.println("<br>");

out.println("<input type=\"radio\" name=\"sex\" value=\"Male\">");

out.println("Male<br>");

out.println("<br>");

out.println("<input type=\"Submit\" name=\"Submit\" value=\"Submit\">");

out.println("</form>");

In the post method I do the following

String getstr=request.getParameter("sex");

if(getstr.equals("male"));

{

out.println("<form method=\"post\" action=\"");

out.println(this.getClass().getName() +"\">");

out.println("<input type=\"text\" name=\"Name\" value=\"Username\">");

out.println("Username <br>");

out.println("<br>");

out.println("<input type=\"password\" name=\"password\" value=\"Password\">");

out.println("Password<br>");

out.println("<br>");

out.println("<input type=\"Submit\" name=\"Submit\" value=\"Save\">");

out.println("</form>");

}

else

{

// will display some different text fields

}

My question is how do I access the values the user entered in the "Username" and "Password" of the Male Form ?

Waiting for your replies,

thanks,

@debug[/nobr]

[2472 byte] By [@debuga] at [2007-11-26 23:41:54]
# 1
use default object in jsp: request<% String firstName = request.getParameter("Username"); %>
abc0xyza at 2007-7-11 15:10:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
But it throws a nullpointerexception. I dont know what I am doing wrong. Can someone point me to some example or links,thanks @debug
@debuga at 2007-7-11 15:10:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
> But it throws a nullpointerexception. I dont know> what I am doing wrong. Where is the exception thrown ?Is the parameter corectly submitted ? Use a sniffer to be sure that the parameter is sent from browser.
abc0xyza at 2007-7-11 15:10:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

thanks I solved it. I was saving these values to a property file before getting them,

but I have one more question:

If the users checks the radion button I want to save the value in property file so that when the users gets back to the form he knows that he checked this radio button previously.

I dont have problems saving and getting values from a property file but I just wanted to get the values of the checked radion button so that it remains checked when the user returns

regards,

@debug

Message was edited by:

@debug

@debuga at 2007-7-11 15:10:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
What are you writting to the propery file now, related to the form ?Why don't use a database ?
abc0xyza at 2007-7-11 15:10:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
I am just practicing now. I dont want to go for database as of now.However, my question was related to the radio button.
@debuga at 2007-7-11 15:10:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

The idea is to use a flag to mark the radio buttons that you selected. You save somehow that flag in the property file (you relate it with the radio button) and when you get the radio from the property file, if the flag is on, you mark it as checked. The flag could be a number (0- no check/1 - check).

abc0xyza at 2007-7-11 15:10:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...