• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Convert Javascript Variable to Servlet variable

 
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;
}
 
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.
 
Ranch Hand
Posts: 312
MS IE Java
  • 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.
 
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..

 
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
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic