Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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: 64633
86
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic