• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to get the name of the current user?

 
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this login page


when login is success i redirect user to home.jsp page.
how can I get the current user name ?
 
Ranch Hand
Posts: 98
Angular Framework Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Send cookies form server with username and access with Javascript.
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Example please
 
Saloon Keeper
Posts: 13248
291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dinesh Kumar Ramakrishnan wrote:access with Javascript.


There's absolutely no reason to use JavaScript. Cookies are sent with each browser request, regardless of whether you send an Ajax request.

Whatever server side language you're using, it must have a way to read and write cookies. When a user logs in, you can save their user name in a cookie, and whenever they access any page on your website, you can read the user name from the cookie and use it to authenticate them.

What server side language are you using?
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need an example.
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java is my erver side language
 
Stephan van Hulst
Saloon Keeper
Posts: 13248
291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What application container and MVC framework are you using?
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RESt Api
 
Stephan van Hulst
Saloon Keeper
Posts: 13248
291
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not what I meant.

Are you using something like Spring MVC, Jersey, etc. or a very basic servlet with JAX-RS?

The best way to deal with this in my opinion is to setup your MVC framework with authentication middleware that handles all of this for you. The framework will then automatically authenticate the user before they hit a resource that requires authentication.

Note that many people prefer to use authentication tokens with a RESTful API, but I don't believe that the use of cookies goes against the principle of REST.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi chamini,

As i understand your problem , you have login page with username and password. Once you submit this form , it will go to first servlet after validating, if logged user is valid you are redirecting to home.jsp.

So when you are sending data to servlet(where you are validating whether it is valid user or not), in servlet you can set user in servlet after redirecting to home.jsp , you can get directly from session(implicit object in jsp) in

home.jsp.

I hope you are clear!!

 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic