• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert Javascript Variable to Servlet variable

 
Janel Blakely
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found javacript that gets current username, how do I set a variable in the servlet to the javascript variable?

<script type="text/javascript">
$(document).ready(function(){
var userLogin = $().SPServices.SPGetCurrentUser({
fieldName: 'Name',
debug: true
});
$('#login').text(userLogin.toString());
});
</script>
...
public String getUserName()
{
return userLogin;
}
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In simple words: you can not, Javascript and servlets are totally different, one runs in browser and one on server.
You can use ajax or a simple GET/POST to send the variable value to server.
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Return the value in the Servlet as the value of a hidden control and access it using JavaScript.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want to set a value of a servlet member in javascript ? if so.. try this... I have not tested it though..

 
Rudy Gireyev
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robin John wrote:Do you want to set a value of a servlet member in javascript ? if so.. try this... I have not tested it though..

It may work better if the textfield was hidden, unless of course you want the user to see this textfield on the screen.

Rudy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic