File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic

How to write to the servlet with standalone application

P Kumar

Joined: Nov 27, 2001
Posts: 4
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.
Client program

import*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import*;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("");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.

import*;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

JSWDK WebServer Version 1.0.1Loaded configuration from: file:E:\jswdk-1.0.1\webserver.xmlendpoint created: localhost/ THREAD PROBLEM: Connection reset by peer: JVM_recv in socket input stream Connection reset by peer: JVM_recv in socket input stream read at Method) at at at at javax.servlet.ServletInputStream.readLine( at com.sun.web.server.ServletInputStreamImpl.readLine( at com.sun.web.server.ServerRequest.readNextRequest( at

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

This is the same post as this.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to write to the servlet with standalone application
It's not a secret anymore!