title: Maintain Session attributte while open new url in webview Android
body: <p>I have a Java/Jsp web application where at search_list.jsp page I am setting the result in the session object like this --</p>
  
  <pre><code>&lt;%
  
    Object resultdata = req.getSession().getAttribute("search_result");
    if(resultdata == null)
    { 
      resultdata  = (SearchResult)getSearchResult();
       request.getSession().setAttribute("search_result", resultdata);
   }
  
  %&gt;
  </code></pre>
  
  <p>From web browser when I hit another page and comeback to search_list.jsp retrieving of result object from session works fine , but same scenario always return > resultdata null in android native webview. Following is the code of webview from android native app.</p>
  
  <pre><code>public class HomeActivity implements OnClickListener {
  
    public WebView mWebView;
    public String sessionCookie =  null;
  
    protected void onCreate(Bundle savedInstanceState) {
  
              mWebView = (WebView) findViewById(R.id.webView1);
              WebSettings webSettings = mWebView.getSettings();
      webSettings.setJavaScriptEnabled(true); 
      webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
      webSettings.setLoadsImagesAutomatically(true);
                mWebView.loadUrl(appPrefer.getAppURL());          
           mWebView.setWebViewClient(new WebViewClient());
  
     }
  
    public void saveSession()
           CookieSyncManager cookieSyncManager =             CookieSyncManager.createInstance(mWebView.getContext());
      CookieManager cookieManager = CookieManager.getInstance();
      cookieManager.setAcceptCookie(true);
      if(mWebView!=null)
      {
              sessionCookie = cookieManager.getCookie(getCurrentURLLoad());               
  
      } 
  
  }
  
  private void addSession(String url) 
    {                 
      CookieSyncManager cookieSyncManager =  CookieSyncManager.createInstance(mWebView.getContext());
      CookieManager cookieManager = CookieManager.getInstance();
      cookieManager.setAcceptCookie(true);            
      if (sessionCookie != null) {            
              cookieManager.setCookie(url, sessionCookie);
              CookieSyncManager.getInstance().sync();         
          }
  
   }
  </code></pre>
  
  <p>This is button click of native where (its kind of shortcut to go result back) i am loading search_list.jsp again for show result. But at web level we already search and shows results and viewing the profile.jsp page. So on click of native listview(url is search_list.jsp) I add session as follow:</p>
  
  <pre><code>public void onClick(View v) {
  if(v.getId().== R.id.listview) 
     {
    saveSession();
    mWebView.loadUrl(HOST_URL + SEARCH_LIST );
        addSession();
      }
   }
  </code></pre>
  
  <p>My problem is its saves/pass all other session cookie values but values set as request.session.attribute not come up they all are >null, after url changes on click from native at jsp level resultdata is always null.</p>
  
  <p><strong>I have tried the method mention in answer, also tried the - <a href="https://gist.github.com/arpit/610754" rel="nofollow">https://gist.github.com/arpit/610754</a>  way and I always see all my cookies correct value(which is already working on my posted que..) .. but Attribute set in HTTPRequest session is not there .. i donot think its part of cookie its a httpRequets attribute ( <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSession.html#setAttribute%28java.lang.String,%20java.lang.Object%29" rel="nofollow">HttpServletRequest->httpSession->setAttribute()</a> ) and my conclusion is its not come at Android webview OR httpclient side. Please someone let me know is that correct or there is a way to read the http request session attribute???</strong> </p>