我想将 Java(POJO 类)对象发送到安装在不同或相同 tomcat 上的其他应用程序。
我在同一个tomcat上使用and和我的两个应用程序时尝试过request.setAttribute("abc",javaObj)
但获得了null
价值。我正在使用重定向 jsp。request.getAttribue("abc")
scope="application"
如果你想在同一个 tomcat 下的两个应用程序之间共享一个变量,那么你需要使用 setAttribute 方法在 servletcontext 中设置它。
要将 POJO 发送到不同的 tomcat 或 JVM,您可以使用 RMI 或 HTTP。
使用 RequestDispatcher 和 setAttribute
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("your url");
MyPojoObject m=new MyPojoObject();
request.setAttribute("abc", m);
dispatcher.forward(request, response);
取回
MyPojoObject mo=(MyPojoObject)request.getAttribute("abc");