Hi Town,
Your code works perfectly fine in my environment. (NT+IIS+Websphere 2.0). After some
meddling, I got
IOException-2, when the Servlet wasn't actually available (ie out of servlet
classpath). You pls check
(typing the servlet url in a browser) whether the servlet is accessible. Hope it
helps.
Ashwath
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hear and you forget; see and you remember; do and you understand. - Confucius
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ashwath Narayan A
Torry Harris Business Solutions
Member - Software Engineering Services
Sona Towers, # 71, Millers Road
Bangalore - 560 052, INDIA
Tel: (+91-80) 2097511 Fax: (+91-80) 2259833
web: www.thbs.com
email: [EMAIL PROTECTED]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DragonTown wrote:
> Hello all,
>
> I try to write a applet to invoke a servlet, but I failed, I don't
> know where I make mistake, here is my source code, feom message box,it
> shows IOException-2, please tell me my mistakes.
> Thanks in advance.
>
> *********************************************************
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class My2Servlet extends HttpServlet
> {
>
> public void service (HttpServletRequest request,
> HttpServletResponse response)
> throws ServletException, IOException
> {
> try
> {
> ObjectInputStream in=new
>ObjectInputStream(request.getInputStream());
> ObjectOutputStream out=new
>ObjectOutputStream(response.getOutputStream());
> String data=(String)in.readObject();
> in.close();
> if (data==null)
> {
> System.out.println("data not trans into
>servlet");
> out.writeObject(new String("error"));
> }
> else
> {
> System.out.println("data trans to servlet
>OK");
> out.writeObject(data);
> }
> out.close();
> }catch (IOException e)
> {
> System.out.println("server side IOException");
> }catch (ClassNotFoundException ce)
> {
> System.out.println("convert string error");
> }
>
> }
> }
>
> ***********************************************************************
> applet's method:
> ***********************************************************************
> void button1_ActionPerformed(java.awt.event.ActionEvent event)
> {
> // to do: code goes here.
> String data=null;
> String message=new String("new message");
> InetAddress localHost=null;
> String localHostAddress=null;
> try
> {
> localHost=InetAddress.getLocalHost();
> localHostAddress=localHost.getHostAddress();
> } catch (UnknownHostException e)
> {
> System.out.println("local host not found");
> }
> URL url=null;
> URLConnection con=null;
> try
> {
> url=new URL("http://"+localHostAddress+"/servlet/My2Servlet");
> con=url.openConnection();
> con.setDoInput(true);
> con.setDoOutput(true);
> ObjectOutputStream out=new ObjectOutputStream(con.getOutputStream());
> out.writeObject(message);
> out.close();
> }catch (MalformedURLException me)
> {
> System.out.println("MalformedURLException");
> }catch (IOException e)
> {
> System.out.println("IOException");
> }
> try{
> ObjectInputStream in=new ObjectInputStream(con.getInputStream());
> data=(String)in.readObject();
> in.close();
> }catch (MalformedURLException me)
> {
> System.out.println("MalformedURLException-2");
> }catch (IOException e)
> {
> System.out.println("IOException-2");
> }
> catch (ClassNotFoundException ce)
> {
> System.out.println("convert string error");
> }
> button1.setLabel(data);
> }
> *******************************************************
>
> Best regards,
> DragonTown mailto:[EMAIL PROTECTED]
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html