Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to write to the servlet with standalone application  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
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)
--------------------------------------------------------------------------------

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is the same post as this.
http://www.javaranch.com/ubb/Forum7/HTML/006912.html

    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!