Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

communication between swing and servlet

 
s. anitha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to Communicate swing to servlet,by passing a string from swing to servlet.Here iam sending the sample code here.please help me.

The problem is i cant able to communicate with the servlet.

Swing part
==========


StringBuffer sb=new StringBuffer("http://localhost:8080/AppletWatch/AppServlet?colwidth=");



for(i=0, len=columnOrderPref.length; i<len; i++)
{
if(i!=0) sb.append(", ");
sb.append(columnOrderPref[i]);
}
try
{
String urlsb = sb.toString();
URL servletURL = new URL(urlsb);
URLConnection connection = servletURL.openConnection();



Servlet Part
============

public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException
{

String msg = req.getParameter("colwidth");
System.out.println("MEssage"+msg);
}
 
Vijay Kiran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error you are gettting in your when you run the swing program?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Where are you actually setting the colwidth value?
 
Vijay Kiran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code that is adding the colwidth param


for(i=0, len=columnOrderPref.length; i<len; i++)
{
if(i!=0) sb.append(", ");
sb.append(columnOrderPref[i]);
}
 
Ivan Tamayo
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try opening a socket to this URL and reading the result.
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after you do the following, you need to actually connect to the URL:



StringBuffer sb=new StringBuffer("http://localhost:8080/AppletWatch/AppServlet?colwidth=");



for(i=0, len=columnOrderPref.length; i<len; i++)
{
if(i!=0) sb.append(", ");
sb.append(columnOrderPref[i]);
}
try
{
String urlsb = sb.toString();
URL servletURL = new URL(urlsb);
URLConnection connection = servletURL.openConnection();

//this is what needs to be added

connection.connect();


--

until u do the connection.connect(), the actual connection is not made.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic