You can call a servlet from any java class. It simply a matter of generating a
http request. Try to read and use java.net.URL and java.net.URLConnection. If
your servlet is taking GET request, it is very easy to call it. Just create a
URL object by passing the url string ( test that url with a browser) and
urlobject.getStream() method. Make a convenient wrapper class object from
java.io package and start reading. If your servlet takes only post request,
here is the code :

 public static Vector submitData(String u, Properties props, int type) {
  Vector data = new Vector();
  URL url = null;
  String query = "";
  Enumeration names = props.propertyNames();

  while(names.hasMoreElements()) {
   String name = (String) names.nextElement();
   String value = props.getProperty(name);
   query += name + "=" + URLEncoder.encode(value);
   if(names.hasMoreElements()) {
    query += "&";
   }
  }

//  System.out.println(query);

  try {
   url = new URL(u);
   URLConnection uc = url.openConnection();
   uc.setDoOutput(true);
   uc.setDoInput(true);
   uc.setAllowUserInteraction(false);
   DataOutputStream dos = new DataOutputStream(uc.getOutputStream());

   // The POST line, the Accept line, and
   // the content-type headers are sent by the URLConnection.
   // We just need to send the date
   dos.writeBytes(query);
   dos.close();

   // Read the response
//   DataInputStream dis = new DataInputStream();

   BufferedReader dis = new BufferedReader(new
InputStreamReader(uc.getInputStream()));

   String nextline;
   while((nextline = dis.readLine()) != null) {
    data.addElement(nextline);
   }
   dis.close();
  }catch(Exception ex) {
  }
  return data;
 }




For better results for GET request use java.net.HttpURLConnection

Sudhir Kumar wrote:

>  hi,
>      Can anyone of u please tell me , If it if possible to call a Servlet
> through AWT - .Frame  directly ???
>
>      thanks in advance..
>      sudhir
>
> ___________________________________________________________________________
> 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

Reply via email to