android webview can‘t get vertx session

來源:互聯網
上載者:User

標籤:vertx session blank

android webview can't get session when using target="_blank" with <a> link.

### 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("/h5/*").handler(StaticHandler.create("web/h5"));    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/h5 file folder,named test3.html and test4.html respectively. test3.html source code:

<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /><title>test3.html</title><script type="text/javascript" src="//cdn.bootcss.com/jquery/2.0.3/jquery.min.js"></script></head><body><div id="myData"></div><div id="myData2"><a href="test4.html" target="_blank">call test4</a></div><script type="text/javascript" charset="utf-8">$.ajax({ url:"/hit?time="+(new Date().getTime()), type:"post", dataType : "json",success: function(resp){console.log(resp)$("#myData").html(resp.data);},error: function(){$j("#myData").html("error.");me.resetload();}});</script></body></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/h5/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



android webview can‘t get vertx session

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.