Tomcat error: java.io.IOException: Server returned HTTP response code: 405 for URL: -


using tomcat. want send string server, have server manipulate string , send back. app crashes whenever try open inputstream on client after have written output stream.

server:

public void doget(httpservletrequest request,       httpservletresponse response) throws ioexception, servletexception{     try{          servletinputstream = request.getinputstream();         objectinputstream ois = new objectinputstream(is);          string s = (string)ois.readobject();          is.close();         ois.close();          servletoutputstream os = response.getoutputstream();          objectoutputstream oos = new objectoutputstream(os);           oos.writeobject("return: "+s);         oos.flush();          os.close();         oos.close();      }     catch(exception e){      } } 

client:

urlconnection c = new url("*****************").openconnection(); c.setdoinput(true); c.setdooutput(true); c.connect();  outputstream os = c.getoutputstream(); objectoutputstream oos = new objectoutputstream(os);  oos.writeobject("this send"); oos.flush(); oos.close();  inputstream = c.getinputstream(); objectinputstream ois = new objectinputstream(is); system.out.println("ret: "+ois.readobject());  ois.close(); is.close(); os.close(); 

it returns error:

java.io.ioexception: server returned http response code: 405 url:  http://mywebpage.com 

what causing error, doing wrong?

you're using http servlets; tomcat running web server. have speak http client, not serialized java objects. if wanting use java serialization, need use sockets. if want use servlets, need use form of putting information http; json (with jackson) choice.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -