我知道的是我在做它错误;我不知道怎么做才对。 以下是Apache servlet的一些代码。从Apache到Android应用程序的Cookie
@覆盖
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/Cookie");// May be wrong
Cookie c = new Cookie("cookie", "CookieS i LOVE");
c.setMaxAge(60*60);response.addCookie(c);
}
For Android app i have this code to get the cookie sent from the that servlet.
Now i want to store that cookie on my android device. and then retrieve it for
another activities.
{....}
public void onClick(View v) {
HttpClient client = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://********:8080/***/servlet");
Cookie c = (Cookie) CookiePolicy.ACCEPT_ALL;
try {
HttpResponse execute = client.execute(httpget);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
List<Cookie> cookies = ((AbstractHttpClient)client).getCookieStore()
.getCookies();
String mycookie = cookies.toString();
Toast.makeText(Cookies.this, mycookie, Toast.LENGTH_SHORT).show();
}
}
}
Thank You for your help.
'然后检索另一个activities'意味着同一个应用程序,但不同的活动或不同applicaitons? –
是的,它是登录,所以第一个屏幕是注册的东西,其余的屏幕是出于商业目的。 –