java - How to make my JAX-RS webservice remember my login? -


i created simple rest webservice in java using jax-rs. , have client make ajax calls webservice login , login information.

jax-rs code

@path("/netsuite") public class myrestwebservice{    @get    @path("/login/{username}")    public string login(@pathparam("username") string username){       //here have save username in session can use in below function    }      @get    @path("/getusername")    public string getusername(){       //here have return above username    }   } 

i know rest webservices stateless, how can make stateful. tried google search whole day, didn't helped me much.

how can make stateful ?

you can access httpsession , store username this:

@get @path("/login/{username}") public string login(@pathparam("username") string username, @context httpservletrequest servletrequest) {     httpsession session = request.getsession();     session.setattribute("username", username); } 

but recommend rethink why need state in stateless application , take @ java ee security concepts.

unrelated: classes in java start capital letter.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -