[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Keeping values after refreshing...

Posted on 2004-09-07
12
Medium Priority
?
307 Views
Last Modified: 2010-04-01
Hi, I am creating a jsp file that has a checkbox and a select box.  There are also two buttons: one "Run" button that will run something give the choices in the checkbox and select box, and the second "Apply Settings" button applies the settings so that if a user presses the "Run" button, the choices that the user picked right before clicking apply settings will be in affect.  Is there a way to keep the choices selected (choices that the user choose after clicking the "Apply Settings" button) even when the user performs a refresh on the page?  Currently, if the user clicks refresh, all the default values are selected.

If possible, please provide some sample code. Any comments or suggestions are well appreciated.

Thanks,
noijet.
0
Comment
Question by:noijet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
12 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 12001278
The only way to persist attributes accross multiple requests is to store the values on the session.  Maybe something like this...

<form name='runForm' method='post'>
<input type='checkbox' name='checkbox1'
    <%if (session.getAttribute('checkbox1')!=null) {
        %>checked='true'<%
     }%>/>
<input type='button' name='run' value='run' onclick='javascript:run()'/>
<input type='button' name='Apply' value='ApplySettings' onclick='javascript:apply()'/>
</form>
<%
  if (request.getMethod().equals("POST") {
     if (request.getAttribute("checkbox1")!=null)
       session.setAttribute("checkbox1", request.getAttribute("checkbox1"));
  }
%>
0
 

Author Comment

by:noijet
ID: 12008013
Thank you MogalManic, I am currently on another urgent project, but I will get back as soon as possible, thanks again!

-noijet
0
 

Author Comment

by:noijet
ID: 12019275
Hi MogalManic, thanks for your comment and sorry for the delay !.  

Is there a way to do this using hidden fields or cookies?  I have always thought cookies are like sessions, am I right?

Thanks,
noijet.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:MogalManic
ID: 12022209
Oh yea,

Sometimes the simplest solutions are the best!  I don;t have time right now to do a full blown and tested page but it would be something like this:

<body onload='setOptions()'>
<form name='runForm' method='post'>
<input type='checkbox' name='checkbox1' >
<input type='button' name='run' value='run' onclick='javascript:run()'/>
<input type='button' name='Apply' value='ApplySettings' onclick='onclick='setCookie("checkbox1", "this.checked", (new Date())+5000 /*5 seconds from now*//)'/>
</form>


To answer your cookie & session question:
The Java servlet uses cookies for the Session ID and the session data is then stored on the server and mapped to the user via the session ID.  This means that sessions are a little more secure than cookies because the user does not directly know what is stored.  If you use an all cookie solution, then the user CAN (probably does not know how) view the cookies on his hard drive.
0
 

Author Comment

by:noijet
ID: 12030959
Thank you for your very informative and excellent answer MogalManic.  Regarding cookies, what risk would it be to allow users to view the cookies on his hard drive, could the user use that to break into my server or something?  I would probably store the user's name, address so that the user doesn't have to type it again on another page or for some other action.

Thank you,
noijet.
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 720 total points
ID: 12031070
no, the cookies just would be the data the client stored.  The client would just know more details on how your page works.  They could manually change the cookie data W/O going through your page.
0
 

Author Comment

by:noijet
ID: 12031108
Thanks MogalManic, so if they do manually change the cookie data, they would only be doing this on their own local machines?

Thanks,
noijet.
0
 

Author Comment

by:noijet
ID: 12031602
Hi MogalManic, an off-topic question, do you know how to get an image next to the web address, sort of like how experts-exchange has it?

(I didn't want to write another question, but I added some points though)
Thanks noijet
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12034173
I'm not sure that I understand the question.  Do you mean this:
   <a href='/nextImage><img src="next.gif"></a>
0
 

Author Comment

by:noijet
ID: 12055404
Thanks MogalManic for your comment, I meant on the Address bar near the top of our webbrowser.  On the left side of "http://www.experts-excha..., there is a image, can we change that?

Thanks again,
noijet.
0
 

Author Comment

by:noijet
ID: 12143327
Hi, I currently have a question open regarding using Tomcat and ServletExec Application servers, if you have some comments please check out question:  "Working with Tomcat and ServletExec on IIS..."     http://experts-exchange.com/Web/Web_Servers/IIS/Q_21143102.html

Thank you !
noijet
0
 

Author Comment

by:noijet
ID: 12435118
Hi everybody !  If possible, can you take a look this question regrading a mysterious scrollbar appearing in Netscape 7.2 but not in Netscape 7.1 or IE?  

At link: http://www.experts-exchange.com/Web/Web_Languages/HTML/Q_21186370.html

Thank you !
noijet
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question