【发布时间】:2016-07-21 10:49:52
【问题描述】:
我有一个 servletOne 在本地 TOMCAT 中运行,而 servletTwo 部署在远程位置的不同 TOMCAT 中。我想访问在 servletTwo 中设置的值(Array/ArrayList)。我不知道该怎么做。我看过不同的例子,但没有任何效果。这就是我到目前为止所拥有的。这是我的doPost
doGet(req, resp);
//doGet
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
ArrayList al = new ArrayList();
al.add("valOne");
al.add("valTwo");
//Should I use this
PrintWriter out = resp.getWriter();
out.println(al);
//Or should I use this
req.setAttribute("ArrayList", al);
}
现在我想从 servletOne 访问数组列表
在 servletOne 我有,
try
{
URL url = new URL("http://myhost:8080/servletTest");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
BufferedReader in =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response;
while ((response = in.readLine()) != null)
{
System.out.println(response);
}
in.close();
}
catch (MalformedURLException ex)
{
// handle this exception
}
catch (IOException ex)
{
// handle this exception
}
}
我不认为它会起作用,因为我从 servletOne 获取字符串而不是数组的值。任何帮助将不胜感激。 提前致谢。
【问题讨论】: