Re: Best way to store variables and user choices in JSP page
"Vajra" wrote:
1. What is the best way to keep user's choices as he surfs and adds options
under each category ? I thought of using session vars , in form of arrays,
but I wonder if there is a better more efficient way ?
shah.rajan@gmail.com wrote:
Please do not top-post.
Well first you should not be using session variables. You can use
hidden fields avaialble in html [sic]
Why not use session variables?
<input type="hidden" name="" value-""> , By using hidden fields you
will be able to get all the values in each page you just need to get
all this values and store it back to the returning page.
At the cost of increased traffic between client and server, and concomitant
security issues, which would not be a problem with session variables.
For the last page editing thing there can be 2 ways to do it
1) Create a link in the jsp page in such a way that all the options
which they have selected goes with it
eg: Sports <a href="Test.jsp?
sports=abc,cde&social=xyz,wxy&option=edit&category=sports"> Edit </a>
Generally you're better off following a Model-View-Controller pattern,
submitting a POST to a controller servlet and having it guide the response
with request parameters, rather than tangling navigation and view in this way.
2) second option is whenever the link is clicked you call a
javascript function which will do a post submit of the page and will
set a value of some variable which will tell whether it was edit or
remove and which category
Sports <a href="#" onClick="DoSomething('Edit','Sports')" > Edit </a>
<script>
Or just use an "Edit" or "Remove" submit button.
While Javascript can sweeten the user experience, it is by no means required
for this scenario.
Use "submit" inputs rather than links. Don't hit JSPs with a GET or POST;
JSPs are for view components. Hit the controller servlet. That servlet will
dispatch a RequestDispatcher.forward() to bring up the correct JSP. Google
"Model-View-Controller", Sun's "Model 2" architecture, and the "Front
Controller Pattern".
--
Lew