Tuesday 15 January 2013

java - Is it possible to get the cookie value over the application? -


I have a different requirement that I have not understood before. Suppose I have two web applications that will run as a host with a local host on the same browser. Is it possible to set cookie pricing in my first web application and get related cookie value in my other web application?

If possible, how can I do this?

I tried the following, but I am getting it as a cookie value null .

In my first web application

  cookie cK = new cookie ("portal user", UN name); Ck.setDomain ("localhost"); Ck.setMaxAge (30 * 60); Response.addCookie (ck);  

In my other web application,

  http session mySession = request.getSession (); System.out.println (mySession.getAttribute ("PortalUser")); // value is blank printing  

You can cookie manager You can try to use and set your cookie policy to ACCEPT_ALL and then use to get the cookie store .

Cookie Manager Cookie Manager = New Cookie Manager (); CookieManager.setCookiePolicy (CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault (cookieManager); // The given string URL creates a URL for url = null; Try {url = new URL ("http: // localhost /"); // Opens a connection with the specified URL and returns the URLConnection object URLConnection urlConnection = url.openConnection (); // specifies urlConnection.getContent the contents of this URL; } Hold (malformedlexception | IOException e) {e.printStackTrace (); } // cookie store (bunch of cookies) cookie cookie cookie = cookieManager.getCookieStore (); // Getting cookies, type list HttpCookie List & lt; HttpCookie & gt; ListOfcookies = cookiestore.getCookies (); (HttpQQ http cookie: listfixes) {System.out.println ("Cookie name:" + httpcookie.getName () + "Cookie value:" + http.cookie.getValue ()); }

No comments:

Post a Comment