I have a Java/Jsp web application where at search_list.jsp page I am setting the result in the session object like this --
<%
Object resultdata = req.getSession().getAttribute("search_result");
if(resultdata == null)
{
resultdata = (SearchResult)getSearchResult();
request.getSession().setAttribute("search_result", resultdata);
}
%>
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.
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();
}
}
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:
public void onClick(View v) {
if(v.getId().== R.id.listview)
{
saveSession();
mWebView.loadUrl(HOST_URL + SEARCH_LIST );
addSession();
}
}
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.
I have tried the method mention in answer, also tried the - https://gist.github.com/arpit/610754 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 ( HttpServletRequest->httpSession->setAttribute() ) 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???