This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JS ---> JSP variables

 
Roberto Diaz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I assign a Java Script variable to a JSP variable.
Both the variables are of string type.
TIA for all responses.
 
arul murug
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is direct way to assign the variable as java script executes at client side and jsp code(as a servlet) at server side.
However u can assign the java script variable to a hidden form field and pass to server where the jsp can get it using request.getParameter().
 
avina metha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this way
<% String string1=request.getParameter("Name");
simillar for others..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what avina is getting at, but getParameter() will not allow you to access JavaScript variables.
arul on the other hand is quite correct. Think about it for a moment.
The JSP executes on the server in order to format the HTML page which is then sent to the browser wherre it (along with any JavaScript contained within) is interpreted by the browser.
They live in completely separate worlds.
Now, as arul pointed out, the value of the JS variable can be made available to the next JSP page by submitting it as a request parameter.
hth,
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic