• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Swing - servlet communication

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i communicate with servlets from swings. I want to send and recieve the data from the servlets to the swings application using JFrame.

Please specify any resources which will give the info.

If u can please give the code for swing servlet communication.

thanks in advance
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this. It works for Swing apps just like it does for applets.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

I know about swing(JApplet) to servlet communication.

But its not working in JFrame,

Why it is i dont know,

Here is the code for JApplet to servlet communication
private URLConnection getServletConnection(String servletName) throws MalformedURLException, IOException
{
URL urlServlet = new URL(getCodeBase(), servletName);
con = urlServlet.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
return con;
}


URLConnection con = getServletConnection("db");
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(fields);
oos.flush();
oos.close();

// receive result from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
details = (ArrayList) inputFromServlet.readObject();

tell me any one how it is in Frame

Thanks in advance
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's going to work except for the "getCodeBase()", which is an applet method. You're going to need to get the servlet URL some other way -- i.e., letting the user type it in, or from a configuration file or something.

But surely if you tried this, the compiler error message already made this clear enough?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But its not working in JFrame,


What does this mean? Is the code being called? Are any exceptions thrown? Is the server accessed at all? Are there exceptions on the server?

It doesn't matter in which class this is implemented, whether it's a subclass of JFrame or not.
 
kalyan chowdary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to get the servlet using this this URL(from JFrame) but the servlet is not responding.

URL url=new URL("http://localhost:8080/ItemDetails/dbmodify");
URLConnection con=url.openConnection();

ItemDetails is my application name,
dbmodify is the urlpattern which is written in web.xml for that particular servlet.

Help me,

Thanks in advance
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kalyan, you need to provide more detail if you want us to help you: TellTheDetails.

E.g., what does this mean:

the servlet is not responding.


Does the request ever get to the server? Does the request ever get to the servlet? Is any of the code of the servlet run? Are there exception, either on the client or the server?
 
kalyan chowdary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I mean servlet is not called
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's impossible to determine what might be going wrong if you don't tell us what's happening in detail. Make sure the URL you're accessing is correct (e.g., at first you seem to call parts of it "db", and then later "dbmodify"), and that the code that calls it is actually being run. Good luck.
 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic