aspose file tools
The moose likes EJB and Other Java EE Technologies and the fly likes problem with connect with URL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and Other Java EE Technologies
Reply Bookmark "problem with connect with URL" Watch "problem with connect with URL" New topic
Author

problem with connect with URL

ravi shankar
Greenhorn

Joined: Nov 27, 2001
Posts: 3
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
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.
////////////////////////////////////////////////////////
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("
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.1
Loaded configuration from: file:E:\jswdk-1.0.1\webserver.xml
endpoint created: localhost/127.0.0.1:8080
HANDLER THREAD PROBLEM: java.net.SocketException: Connection reset by peer: JVM_recv in
socket input stream read
java.net.SocketException: Connection reset by peer: JVM_recv in socket input stream rea
d
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:6
0)
at javax.servlet.ServletInputStream.readLine(ServletInputStream.java:100)
at com.sun.web.server.ServletInputStreamImpl.readLine(ServletInputStreamImpl.ja
va:94)
at com.sun.web.server.ServerRequest.readNextRequest(ServerRequest.java:58)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:71)

 
IntelliJ Java IDE
 
subject: problem with connect with URL
 
Threads others viewed
RemoteException
How to write to the servlet with standalone application
a servlet running error and how to get rid of it
Problem while connecting to Servlet
what does this Exception mean???thanx!@!!!
IntelliJ Java IDE