Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: Problem with swing-servlet communication??


Message #1 by bikashpaul_2001@y... on Wed, 29 Jan 2003 05:33:43
Hi Bikash,
you are wel come.

Regards,
- Ravi

-----Original Message-----
From: bounce-servlets-674426@p...
[mailto:bounce-servlets-674426@p...]On Behalf Of Bikash Paul
Sent: Thursday, January 30, 2003 11:00 AM
To: Servlets
Subject: [servlets] RE: Problem with swing-servlet communication??


Hi Ravi,

Thanks for ur help.Now my swing interface is working
properly.

Thanks
Bikash
--- Ravi Prasad <raviprasad@s...> wrote:
> Bikash,
> Yes, you can use URL appended and by using
> request.getParameter(""); you can
> get the Use rid password, but you have to complete
> the cycle as I mentioned
> in the earlier mail.
> Ravi
>
> -----Original Message-----
> From: bounce-servlets-674426@p...
> [mailto:bounce-servlets-674426@p...]On
> Behalf Of Bikash Paul
> Sent: Wednesday, January 29, 2003 12:45 PM
> To: Servlets
> Subject: [servlets] RE: Problem with swing-servlet
> communication??
>
>
> Hi ravi,
>
> First of all thanks for ur help.But I want to send
> only userId and password from my swing interface to
> my
> servlet just like as we do in case of html file for
> that If I send it as query string with the url and I
> get it in servlet by reuest.getParameter();for that
> should i have write it on outputStream and in
> servlet
> should I read it by InputStream.Plz explain me.
>
> Regards
> Bikash
>
> --- Ravi Prasad <raviprasad@s...> wrote:
> > Hi Bikash,
> >
> > Please verify weather you are writing and reading
> > to/from the streams.
> > I mean , if you open 'OutputStream' for writing
> from
> > your swing interface,
> > then you need to read some information from
> > 'InputStream' at swing interface
> > end. and at servlet end , when you read from
> > 'InputStream' you have to write
> > back to 'OutputStream' to complet the cycle.
> >
> > here is the sample
> > Swing Interface(inside the action listner
> > method....):
> > 	    try
> > 	    {
> > 	    	String ps_Url	
> >
>
"http://127.0.0.1:8080/examples/servlet/loginServlet";
> > 		java.net.URLConnection lo_ServletConnection 
> > null;
> > 	        java.net.URL po_Url=new
> > java.net.URL(ps_Url);
> >
> > lo_ServletConnection=po_Url.openConnection();
> > 	        lo_ServletConnection.setDoInput(true);
> > 	        lo_ServletConnection.setDoOutput (true);
> > 	        lo_ServletConnection.setUseCaches
> (false);
> > 	        lo_ServletConnection.setDefaultUseCaches
> > (false);
> >
> >
>
lo_ServletConnection.setRequestProperty("content-type","application/octet-st
> > ream");
> >
> > 		Object lo_SendInfoToServlet	=	new Object();
> > 	        java.io.ObjectOutputStream
> lo_OutStream=new
> >
>
java.io.ObjectOutputStream(lo_ServletConnection.getOutputStream());
> >
> > lo_OutStream.writeObject(lo_SendInfoToServlet);
> > 	        lo_OutStream.flush();
> > 	        lo_OutStream.close();
> >
> > 		Object lo_FromServlet = null;
> > 	        java.io.ObjectInputStream lo_InStream=new
> >
>
java.io.ObjectInputStream(lo_ServletConnection.getInputStream());
> > 	        lo_FromServlet 
> lo_InStream.readObject();
> > 	        lo_InStream.close();
> > 	    }
> > 	    catch(Exception lo_ExceptionOnSend)
> > 	    {
> > 	        System.out.println("Exception occured
> when
> > sending the data from
> > the applet to servlet::");
> > 	        lo_ExceptionOnSend.printStackTrace();
> > 	    }
> >
> > Servlet:
> >     public  void service(HttpServletRequest req,
> > HttpServletResponse
> > res)throws ServletException,
> > IOException//synchronized
> >     {
> > 	try
> > 	{
> > 			ObjectInputStream lo_InputStream	=	new
> > ObjectInputStream(req.getInputStream());
> > 			lo_RcvdParameter					
> > (Object)lo_InputStream.readObject();
> > 			lo_InputStream.close();
> > 			..................
> > 			..................processing..............
> > 			..................
> > 			ObjectOutputStream lo_OutPutStream=new
> > ObjectOutputStream(res.getOutputStream());
> > 			lo_OutPutStream.writeObject(new Object());
> > 			lo_OutPutStream.flush();
> > 			lo_OutPutStream.close();
> > 	}
> > 	catch(Exception e)
> > 	{}
> >    }
> > Hope this solves your problem...
> > Regards
> > Ravi
> >
> > -----Original Message-----
> > From: bounce-servlets-674426@p...
> > [mailto:bounce-servlets-674426@p...]On
> > Behalf Of
> > bikashpaul_2001@y...
> > Sent: Wednesday, January 29, 2003 5:34 AM
> > To: Servlets
> > Subject: [servlets] Problem with swing-servlet
> > communication??
> >
> >
> > Hi all friends,
> >
> > I couldn't connect my servlet from my swing
> > interface.I want to send two
> > parameters(userid and password) from swing
> > interface(it is a login dialog
> > box) to my servlet.Iam using Tomcat server4.0 and
> I
> > also put entry of my
> > servlet in web.xml file.Can any one plz guide me
> how
> > I can slove this
> > problem.
> > Below r my codes:-
> >
> > Swing Interface(Iam pasting only action event of
> my
> > submit button):-
> > ================
> > public URL u;
> > public URLConnection uc;
> > submit.addActionListener(new ActionListener()
> >  {
> >    public void actionPerformed(ActionEvent e)
> >       {
> >        	String userid1;
> > 	String password1;
> >         String Content;
> >         String
> >
>
url="http://127.0.0.1:8080/examples/servlet/loginServlet";
> > 	userid1 = userid.getText();
> > 	password1 = password.getText();
> >         System.out.println(userid1);
> >         System.out.println(password1);
> >         Content= userid1 + password1;
> >
> >
> >         u = new URL(url+"?name=" +userid1 +
> "&path="
> > + password1);
> >         uc =u.openConnection();
> >         uc.setDoOutput(true);
> >         uc.setDoInput(true);
> >         uc.setUseCaches(false);
> >         printout = new
> > DataOutputStream(uc.getOutputStream ());
> >         printout.writeBytes(Content);
> >         printout.flush();
> >         printout.close();
> >        }catch(Exception
> > ex){System.out.println("Error from
> > actionPerformed :" + ex.getMessage());}
> >                     }
> > });
> >
> > Servlet file:-
> > =============
> > import java.io.*;
> > import java.util.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
>
=== message truncated ===


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



  Return to Index