aspose file tools*
The moose likes Servlets and the fly likes How to write to the servlet with standalone application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

How to write to the servlet with standalone application

P Kumar
Greenhorn

Joined: Nov 27, 2001
Posts: 4
Hi,
I am getting problem when I am trying to connnect the servlet with stand alone java application using URLConnection.Here I Am sending the code and console output from JSWK server.Please give the solution.
thanks.
////////////////////////////////////////////////////
Client program

code:
--------------------------------------------------------------------------------
import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.*;class Upload {public static void main(String[] args) throws Exception{try {String url = "http://localhost:8080/servlet/UpTest";URL uploadurl = new URL(url);System.out.println("After URL");URLConnection uc = uploadurl.openConnection();System.out.println("After getting connection");uc.setDoOutput(true); File fs = new File("GetMessage.java");ObjectOutputStream os = new ObjectOutputStream(uc.getOutputStream());System.out.println("After connecting to servlet");os.writeObject(fs);System.out.println("written successfully"); os.close();}catch(Exception e) {System.out.println("After getitng ....");}}}
--------------------------------------------------------------------------------

//////////////////////////////////////////////////////////////
Servlet program.
////////////////////////////////////////////////////////

code:
--------------------------------------------------------------------------------
import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;//import com.oreilly.servlet.MultipartRequest;public class UpTest extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); try { InputStream ins = req.getInputStream(); out.println("<HTML><HEAD><TITLE>"); out.println("Testing"); out.println("</TITLE></HEAD><BODY>"); out.println("<H1>" + "Testing" + "</H1>"); out.println("<P>This is output from Uploading"); out.println("</BODY></HTML>");out.close();}catch(Exception e) {System.out.println("After getting ....");} }}
--------------------------------------------------------------------------------
/////////////////////////////////////////////////////////
console output is
/////////////////////////////////////////////////////////

code:
--------------------------------------------------------------------------------
JSWDK WebServer Version 1.0.1Loaded configuration from: file:E:\jswdk-1.0.1\webserver.xmlendpoint created: localhost/127.0.0.1:8080HANDLER THREAD PROBLEM: java.net.SocketException: Connection reset by peer: JVM_recv in socket input stream readjava.net.SocketException: Connection reset by peer: JVM_recv in socket input stream read at java.net.SocketInputStream.socketRead(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:90) at java.net.SocketInputStream.read(SocketInputStream.java:106) at com.sun.web.server.ServletInputStreamImpl.read(ServletInputStreamImpl.java:60) at javax.servlet.ServletInputStream.readLine(ServletInputStream.java:100) at com.sun.web.server.ServletInputStreamImpl.readLine(ServletInputStreamImpl.java:94) at com.sun.web.server.ServerRequest.readNextRequest(ServerRequest.java:58) at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:71)
--------------------------------------------------------------------------------

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

This is the same post as this.
http://www.javaranch.com/ubb/Forum7/HTML/006912.html

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to write to the servlet with standalone application