| Author |
How to make a decision on a jsp form ?
|
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
Hi i have the following HTML code in my jsp
I retrieve a value from session using my JSP
<%=session.getAttribute("status")%>
in response i get a P,F,A for (Pass,fail, and absent)
Now There are 3 radio buttons on my jsp page:
but i only want one of the options marked on the basis of the above result how can i do that ??
I guess i can do something like:
but thats not working.. I would like to know what you guys suggest..thanks...
|
Don’t look where you fall, but where you slipped
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
Adam Zedan wrote:but thats not working..
That's not very helpful. Read: ItDoesntWorkIsUseless.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
I would suggest ditching the scriptlets and switching to JSTL and EL. Here's how you would do that in EL:
|
 |
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
Bear Bibeault wrote:
Adam Zedan wrote:but thats not working..
That's not very helpful. Read: ItDoesntWorkIsUseless.
sorry i was unclear before... my bad.
anyways i tried to use the following code in my jsp but the option did not get marked porbably cause checked did not get written
<input name="status" type="radio" <% if(session.getAttribute("status")=="P"){checked} %> /> Pass
|
 |
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
Adam Zedan wrote:
Bear Bibeault wrote:
Adam Zedan wrote:but thats not working..
That's not very helpful. Read: ItDoesntWorkIsUseless.
sorry i was unclear before... my bad.
anyways i tried to use the following code in my jsp but the option did not get marked porbably cause checked did not get written
<input name="status" type="radio" <% if(session.getAttribute("status")=="P"){checked} %> /> Pass
thanks that did the trick but could you also tell me how to accomplish the same task using scriptlet?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
Adam Zedan wrote:thanks that did the trick but could you also tell me how to accomplish the same task using scriptlet?
Was that referring to my post? If so, no, I couldn't. I don't use them any more.
|
 |
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
One more thing... initially when an attribute doesnot exist and on my jsp page i use
<td><input type="text" name="textname" value=<%=session.getAttribute("name")%> /></td>
I get NULL value. Is there any way by which i can just have an empty value ?? or will i have to check for NULL and replace it with empty ??
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
Adam Zedan wrote:but could you also tell me how to accomplish the same task using scriptlet?
If it's working, why would you want to resort to discredited scriptlets?
|
 |
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
Bear Bibeault wrote:
Adam Zedan wrote:but could you also tell me how to accomplish the same task using scriptlet?
If it's working, why would you want to resort to discredited scriptlets?
I guess i should stick to JSTL and EL.. The best way is to not use them.. Thanks for the encouragement...
though i figured it out lol.. just had to use out.println(" checked") in the condition.. But ill stick to Extended language Version... thanks guys..
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
Adam Zedan wrote:One more thing... initially when an attribute doesnot exist and on my jsp page i use
<td><input type="text" name="textname" value=<%=session.getAttribute("name")%> /></td>
I get NULL value. Is there any way by which i can just have an empty value ?? or will i have to check for NULL and replace it with empty ??
Well, yes. The EL automatically does that for you.
|
 |
 |
|
|
subject: How to make a decision on a jsp form ?
|
|
|