Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass a javascript variable value from a JSP page to a Servlet?

 
dukeRavi yadav
Greenhorn
Posts: 2
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scenario:I have a JSP page named "menu.jsp". On this page the user have to choose a choice from a menu and i have implemented onclick("myredirect(choiceValue)") on each menu item using javascript...
this function uses confirm pop-up box to check whether the user want to continue with his current choice.. if user select ok then it'll return true and it will be stored in check variable...
now i want to send this choiceValue to a servlet named "CheckLogin.java" which checks whether the user is logged in using session tracking ..if the user isn't logged in he'll be redirected to "login.jsp" page
otherwise he'll be redirected to "instructions.jsp" page
..i have implemented the whole stuff as below...and i want to use the "choiceValue" throught the session but its not working as i expected....Please somebody help me !!!


"menu.jsp"
#########



"CheckLogin.java"
#################
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you calling your menu.jsp?



Instead of checking the session as null or new , you should set an user object as an atttribute in session when you first login to your application and then check its value in servlet filter (filter should exclude your login url, otherwise you will end up in a loop) so that you can keep track of user session.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic