当前位置: 技术问答>java相关
applet 调用 servlet 问题 ,急
来源: 互联网 发布时间:2015-06-18
本文导语: applet 代码如下: java.net.URL url1 = new java.net.URL("http://localhost:8080/platform/servlet/STOREDATA"); java.net.URLConnection con1 = url1.openConnection(); con1.setDoOutput(true); con1.setUseCaches(false); con1.setDoInput(true); con1.setRequestPrope...
applet 代码如下:
java.net.URL url1 = new java.net.URL("http://localhost:8080/platform/servlet/STOREDATA");
java.net.URLConnection con1 = url1.openConnection();
con1.setDoOutput(true);
con1.setUseCaches(false);
con1.setDoInput(true);
con1.setRequestProperty("Content-type", "application/octet-stream");
PrintWriter out1 = new PrintWriter(con1.getOutputStream());
out1.println("this is test");
out1.flush();
out1.close();
Servlet 代码如下:
BufferedReader in = new BufferedReader(new InputStreamReader (request.getInputStream()));
System.out.println(in.readLine());
tomcat 报错:2002-06-07 09:51:45 - Ctx( ): 400 R( /) null
请帮忙.
java.net.URL url1 = new java.net.URL("http://localhost:8080/platform/servlet/STOREDATA");
java.net.URLConnection con1 = url1.openConnection();
con1.setDoOutput(true);
con1.setUseCaches(false);
con1.setDoInput(true);
con1.setRequestProperty("Content-type", "application/octet-stream");
PrintWriter out1 = new PrintWriter(con1.getOutputStream());
out1.println("this is test");
out1.flush();
out1.close();
Servlet 代码如下:
BufferedReader in = new BufferedReader(new InputStreamReader (request.getInputStream()));
System.out.println(in.readLine());
tomcat 报错:2002-06-07 09:51:45 - Ctx( ): 400 R( /) null
请帮忙.
|
This error occurs when the applet do not read servlet message,
take a look at my example:
Appelt:
private Object[][] getConfigInfo() throws MalformedURLException, IOException{
URL url = new URL(/tech-qa-java/servletForecastUrl/index.html);
URLConnection con = url.openConnection();
con.setUseCaches(false);
Object[][] configData;
try
{
ObjectOutputStream outputToServlet = null;
con.setDoOutput(true);
outputToServlet = new ObjectOutputStream(con.getOutputStream());
// serialize the object
outputToServlet.writeObject("Get System Configuration");
outputToServlet.flush();
outputToServlet.close();
}catch (IOException se){
JOptionPane.showMessageDialog(null, "Can not connect to server!", "Server error", JOptionPane.PLAIN_MESSAGE);
}
try{
InputStream in = con.getInputStream();
ObjectInputStream objStream;
objStream = new ObjectInputStream(in);
configData = (Object[][])objStream.readObject();
return configData;
}catch(Exception re){
//JOptionPane.showMessageDialog(null, "Can not connect to server!", "Server error", JOptionPane.PLAIN_MESSAGE);
}
return null;
}
take a look at my example:
Appelt:
private Object[][] getConfigInfo() throws MalformedURLException, IOException{
URL url = new URL(/tech-qa-java/servletForecastUrl/index.html);
URLConnection con = url.openConnection();
con.setUseCaches(false);
Object[][] configData;
try
{
ObjectOutputStream outputToServlet = null;
con.setDoOutput(true);
outputToServlet = new ObjectOutputStream(con.getOutputStream());
// serialize the object
outputToServlet.writeObject("Get System Configuration");
outputToServlet.flush();
outputToServlet.close();
}catch (IOException se){
JOptionPane.showMessageDialog(null, "Can not connect to server!", "Server error", JOptionPane.PLAIN_MESSAGE);
}
try{
InputStream in = con.getInputStream();
ObjectInputStream objStream;
objStream = new ObjectInputStream(in);
configData = (Object[][])objStream.readObject();
return configData;
}catch(Exception re){
//JOptionPane.showMessageDialog(null, "Can not connect to server!", "Server error", JOptionPane.PLAIN_MESSAGE);
}
return null;
}