Background:
I am trying to send data from a class called from an applet to a servlet all on the same server.
public class SendData {
public void send() {
URL url = new URL("http://address.edu/folder/package/Servlet.class");
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
ObjectOutputStream objout = new ObjectOutputStream(conn.getOutputStream());
Object data = new Object();
objout.writeObject(data);
objout.flush();
objout.close();
}}
The servlet looks like:
public class Servlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
ObjectInputStream objin = new ObjectInputStream(req.getInputStream());
Object input = objin.readObject();
objin.close();
resp.setStatus(HttpServletResponse.SC_OK);
...// do other things
}}
Problem:
The error returned is java.io.IOException: Server returned HTTP response code: 405 for URL: http://address.edu/folder/Servlet.class
. I am using my school's server, and I am not 100% sure, but I don't think the server allows the doPost method.
Is there any way around this? Could I somehow connect via ftp to the servlet.class if I provide the username and password that grants access? I am a complete beginner with this, so any advice/suggestion would be greatly appreciated!
EDIT: added web.xml
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>package.Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/Servlet</url-pattern>
</servlet-mapping>
</web-app>