Here is my Java Class by which I am calling simple servlet and passing the data, I am
using URL and HttpURlConnection class.What should be path of url for the servlet
public class TestJava
{
public static void main(String[] args)
{
try
{
URL url=new URL("http://localhost:9865/TestingServlet/PushServlet");
HttpURLConnection http_url =(HttpURLConnection)
url.openConnection();
http_url.setRequestMethod("POST");
http_url.setDoOutput(true);
http_url.setDoInput(true);
InputStream response = http_url.getInputStream();
System.out.println(" " +response);
ObjectOutputStream objOut = new
ObjectOutputStream(http_url.getOutputStream());
objOut.writeObject("hello");
objOut.flush();
objOut.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
Here is the servlet code, I am receiving the object from the java code and displaying
it on the console.
public class PushServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
try
{
System.out.println("HELLO This is servlet");
ObjectInputStream objIn = new
ObjectInputStream(request.getInputStream());
TestJava p = null;
p = (TestJava) objIn.readObject();
System.out.println("Servlet received p: "+p);
}
catch (Throwable e)
{
e.printStackTrace(System.out);
}
}
My web.xml is like this
<welcome-file-list>
<welcome-file>
Customer_Servlet
</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>PushServlet</servlet-name>
<servlet-class>com.servlet.PushServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PushServlet</servlet-name>
<url-pattern>/PushServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>50</session-timeout>
</session-config>
</web-app>
When i m trying to run the java code on server i.e Apache server, I'm getting
error HTTP Status 404 i am not able to find why i am getting this server error
My code is all about invoking the servlet from java application
please help me guys .