rest - How do we Access Java Restful Web services session variables in HTML5 & javascript -


i'm working on hybrid mobile app development. have developed restful web services in java , need session value in html page i.e client side. how maintain session in javascript?.

here restful webservice

@context private httpservletrequest request;  @get @path("session") @produces(mediatype.text_html) @consumes(mediatype.application_form_urlencoded) public string session(@queryparam("lname") string name1) {     string response2 = null;     string name11 = "kheerthi";     try {          // jdbc connection         resultset rs = pst.executequery();         resultsetmetadata rsmd = rs.getmetadata();         int cols = rsmd.getcolumncount();         while (rs.next()) {             if (rs.getstring(1) != "null") {                 request.getsession(true);                 httpsession session = request.getsession();                 session.setattribute("name", "value");                 session.setattribute("username", rs.getstring(2));                 string username = (string) session.getattribute("username");                 system.out.println(username);             }         }     } catch (exception e) {         e.printstacktrace();     }     return "fail"; } 

here frontend code

$(document).ready(function() {     $("#btn4").click(function() {         alert("button clicked");         $lname = $("#lname").val();         alert("function called1");         alert($lname);         $.ajax({             url: 'http://localhost:8080/samplerestful_demo/webresources/generic/session',             data: {lname: $lname},             type: 'get',             crossdomain: true,             contenttype: 'html/text',             datatype: 'text',             cache: false         }).done(function(response) {            if (response == 'success') {               // var value = '@request.requestcontext.httpcontext.session["username"]';                window.location.replace("http://localhost:8383/html5application1/listform.html");             }             else {                 alert("else called");                  window.location.replace("http://localhost:8383/html5application1/login1.html");             }         }).fail(function(request, textstatus, errorthrown) {             alert(textstatus + " : " + errorthrown.tostring());         });     }); }); 


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -