简体   繁体   中英

During Calling a servlet from another Servlet that contains session

I have 3 Servlets :

  • Servlet1 - is used to create a session by : session = request.getSession(true)
  • Servlet2 - is used to display content of Servlet1
  • Servlet3 is used to call Servlet2 by :HttpURLConnection connectionx = (HttpURLConnection) url .openConnection(); to get the result as :

BufferedReader reader = new BufferedReader(new InputStreamReader(((HttpURLConnection)
    (new URL(the_url)).openConnection()).getInputStream(), Charset.forName("UTF-8")));

The problem is that : I found it when I Run Servlet1 to create the session then I run Servlet 3 to call Servlet2 ...> I got that 'servlet 2' Can not read from the created session..

But if I run Servlet2 directly from Browser I got a session.

What is the problem with Servlet2 and how can I solve it ?!

当您使用HttpClient从Servlet 3调用Servlet 2时,您错过了传递JSESSIONID cookie的机会。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM