android webview can't get session when using target="_blank" with link.
創(chuàng)新互聯(lián)建站是一家專業(yè)提供涼山州企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、H5場景定制、小程序制作等業(yè)務(wù)。10年已為涼山州眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。### Version 3.5.1 (maybe 3.5.0 included,not sure)
* vert.x core:
* vert.x web:
### Context
I used android webview to call a vertx url,when I switched from one page to another, the vertx server would always generate a new session id, so I lost session data set by previous page.
But,when I use iphone webview or PC Chrome to call the same vertx server, the session can be remembered correctly. so the error is only subject to android webview
### Do you have a reproducer?
we can reproducer the error following the steps below.
### Steps to reproduce
1. write a smiple verticle
public class Test1Verticle extends AbstractVerticle { Router router1 ; @Override public void start() throws Exception { router1 = Router.router(vertx); router1.route().handler(CookieHandler.create()); router1.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router1.route("/h6/*").handler(StaticHandler.create("web/h6")); router1.route("/hit").handler(this::hit); vertx.createHttpServer().requestHandler(router1::accept).listen(8080) ; } private void hit(RoutingContext routingContext) { Session session = routingContext.session(); Integer cnt = session.get("hitcount"); cnt = (cnt == null ? 0 : cnt) + 1; session.put("hitcount", cnt); routingContext.response().putHeader("content-type", "application/json;charset=UTF-8") .end(new JsonObject().put("data", "cnt="+cnt) ); } }
2. place 2 html files in the web/h6 file folder,named test3.html and test4.html respectively. test3.html source code:
test3.html
the source code of test4.html is similar to the above,just replace the href to test3.html
3. ...
start the vertx verticle, and open an android browser,input the url (http://192.168.0.13:8080/h6/test3.html) in the browser,then submit
4. you can find ,after jump to the other html,the hit count remains to 1, but if you call the url in iphone or PC browser, the hit count will be found to increment correctly.
5,if we remove the target="_blank" in the html file, the session will work properly
2018-04-21 13:42 update:
I tested on several android phone ,and foud that the session problem did not appear on all android phone, Mi and Huawei could reproduce this error,but sumsung and Lenovo worked correctly.
at last,I added some code in my verticle file to address this problem:
//to make session work correctly on Huawei phone, set Cookie Path to root '/' SetccList=routingContext.cookies(); for(Cookie ck:ccList){ ck.setPath("/"); }
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。