• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I write setter n getter for select tag?  RSS feed

 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
In my web application i've a jsp file in which i have a select tag.
I navigate that jsp to another jsp where i need to get the selected value.
Can i write setter() n getter() for that n get those values??I tried but i'm not getting.
Thanks,
Sandhya.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly. "n" is not a word. Please use real words such as "and" when posting.

Secondly, in order to obtain the submitted value of any HTML control, a select or otherwise, you don't write setters and getters, you use the API of the request. In this case, the getParameter() method.
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I tried with request.getParameter().I didn't get thats the reason i'm using setter and getters.Can you tell me when should i use setter and getters??
this is my code.
one.jsp:
<select name="language">
<option value="Java">Java</option>
<option value="Asp.Net">Asp.Net</option>
</select>
in my next jsp ie two.jsp:
<%String lang=request.getParameter("language");
out.println(lang);%>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getters and setters (more properly called mutators and accessors, respectivley) are part of the JavaBean pattern. When you are creating beans to use on your JSP page, you would use this pattern to ensure that your beans are really beans.

They have little to do with obtaining the value of a submitted control unless you are using a bean to collect and represent the submitted data. Which you are not.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that you have changed your display name from one that was valid, to one that is not.

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!