File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes communication between swing and servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "communication between swing and servlet" Watch "communication between swing and servlet" New topic
Author

communication between swing and servlet

s. anitha
Greenhorn

Joined: Jan 18, 2005
Posts: 18
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

Joined: Nov 18, 2004
Posts: 21
What is the error you are gettting in your when you run the swing program?


Vijay<br />I blog, therefore I am<br /><a href="http://www.vijaykiran.com" target="_blank" rel="nofollow">www.VijayKiran.com</a>
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410



Where are you actually setting the colwidth value?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Vijay Kiran
Greenhorn

Joined: Nov 18, 2004
Posts: 21
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

Joined: Aug 13, 2001
Posts: 49
Try opening a socket to this URL and reading the result.
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: communication between swing and servlet