• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Sample code of Applet call servlet

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone get me sample code of applet which is calling servlet
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at java.net.URLConnection. Create a java.net.URL instance with the URL of the servlet, create an instance of URLConnection and use the various methods of URLConnection to interact with the servlet (i.e. doInput() to POST data or getContent to download). NOTE: An unsigned applet can only establish connections with the same server it was loaded from.
[ February 06, 2004: Message edited by: Joe Ess ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public Vector PopDat()
{
Vector vf=new Vector();
try
{
URL studentDBservlet = new URL( "http://jahanzeb:8080/servlet/QuerySer?Qname="+ap.getParameter("Per"));
URLConnection servletConnection = studentDBservlet.openConnection();
BufferedReader inFromServlet = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
String str;
while (null != ((str = inFromServlet.readLine())))
{
vf.add(str);
System.out.println(str);
}


}catch(Exception e)
{
System.out.println(e.toString());
}

return vf;
}
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello !!!
You can do this also
----------------
(Code in Applet)
URL helloServletURL = new URL( getCodeBase().toString()+ "HelloServlet" );
URLConnection urlConnection = helloServletURL.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);

ObjectOutputStream objOut = new ObjectOutputStream (urlConnection.getOutputStream());
objOut.writeUTF(Id); // pass parameter to servlet
objOut.flush();

ObjectInputStream objIn = new ObjectInputStream(urlConnection.getInputStream());
String state = objIn.readUTF(); // read String from Servlet
----------------
(Code in Servlet)
ObjectInputStream dataInput = new ObjectInputStream(request.getInputStream());
String id = dataInput.readUTF();
ObjectOutputStream dataOutput = new ObjectOutputStream(response.getOutputStream());
dataOutput.writeUTF(status);
dataOutput.flush();
dataInput.close();
dataOutput.close();
--------------------
Purvi Pandya
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic