wood burning stoves 2.0*
The moose likes JSP and the fly likes How to keep the selected value ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to keep the selected value ?" Watch "How to keep the selected value ?" New topic
Author

How to keep the selected value ?

Manu Dhanda
Greenhorn

Joined: Jan 28, 2006
Posts: 23
Hii

I am trying to display the selected value after submitting my page.
Here I am using the below code:


But, in the above written code, "thisdate" inside the option tag is giving me error. "thisdate cannot be resolved"

I couldn't see any mistakes in my code.

Am I missing something?? Please help me out..

Thanks.


"Books are as useful to a stupid person <br />As a mirror is useful to a blind person." <br /> <br />Chanakya quotes (Indian politician, strategist and writer, 350 BC-275BC)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

This question is more about JSP than HTML, so it has been moved to the JSP forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

In the expression

<%= thisdate.equals(myDate)? "selected" :"" %>

what is thisdate?

You did not show us where and how the thisdate scripting variable was defined.
[ October 02, 2006: Message edited by: Bear Bibeault ]
Manu Dhanda
Greenhorn

Joined: Jan 28, 2006
Posts: 23
In my code, the very first line says it as :

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why don't you post the code to the entire select list?
This will give us a better idea of what's going on in your JSP.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Manu Dhanda
Greenhorn

Joined: Jan 28, 2006
Posts: 23
Hi Ben,

This is the code I am using in my JSP SELECT OPTION.


Here, "thisdate" is the name of the SELECT element on the form. I am not using it anywhere else on my JSP page.
And while I 'll access my page, it gives me this error "thisdate cannot be resolved"
I don't have the access right now, I 'll drop the code again as soon as I 'll reach to office.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Originally posted by Manu Dhanda:
In my code, the very first line says it as :



That is just client-side HTML template text and has nothing at all to do with your JSP code.

If you want to compare the submitted value you'll need to get it to the JSP page using a server-side mechanism.
[ October 02, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Perhaps you could benefit from reading this article which outlines how JSPs operate.
[ October 02, 2006: Message edited by: Bear Bibeault ]
Manu Dhanda
Greenhorn

Joined: Jan 28, 2006
Posts: 23
ok, Now this is my entire JSP file.


Everything is working fine in this JSP file.
It started me giving problem when I inserted the following in my <OPTION> tag.



Earlier. I mean to say "The very first line of my code".. It was respective term to this post only, not to my entire JSP file.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Originally posted by Manu Dhanda:

Earlier. I mean to say "The very first line of my code".. It was respective term to this post only, not to my entire JSP file.


Yes, I understood that.



It started me giving problem when I inserted the following in my <OPTION> tag.



That's because, as I already explained, the line containing the select element declaration is meaningless to your JSP code. It might just as well have been "asjdhsdajhgdjagfjsgdafjdhgfjdshgfjdsfaj" as far as your JSP code is concered. It's just template text.

Did you read the article I linked to? You apparantly have a fundamental (and common) misunderstanding regarding how JSPs operate and what is meaningful on the server side versus the client side.
[ October 02, 2006: Message edited by: Bear Bibeault ]
Manu Dhanda
Greenhorn

Joined: Jan 28, 2006
Posts: 23
Thanks Bear Bibeault..

I got it where I was making the mistake.

Changing "thisdate" to "request.getParameter("thisdate")" resolved my problem.

The document 'n then your following words helped me to find out like where I was making the mistake.

That's because, as I already explained, the line containing the select element declaration is meaningless to your JSP code. It might just as well have been "asjdhsdajhgdjagfjsgdafjdhgfjdshgfjdsfaj" as far as your JSP code is concered. It's just template text.


Thanks.
Manu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Excellent. Understanding the fundamental workings of JSP will make them so much easier to work with.
 
 
subject: How to keep the selected value ?