我有一个桌面应用程序通过以下方法调用servlet:
public int[] identify(String path) {
try {
URL url = new URL("http://localhost:8084/my-webapp/upload");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
out.write("path=" + path);
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response;
while ((response = in.readLine()) != null) {
int[] numbers = convertOutput(response);
s.showOutput(numbers);
return numbers;
}
in.close();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
return null;
}
我没有jsp文件。它由桌面应用程序执行,并且可以正常运行。但是现在当我调用我的servlet时,我需要将一个我之前实例化过的对象传递给servlet。我怎么能这样做?