aspose file tools*
The moose likes Servlets and the fly likes Problem with swing-servlet communication?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with swing-servlet communication??" Watch "Problem with swing-servlet communication??" New topic
Author

Problem with swing-servlet communication??

Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi all friends,
I couldn't connect my servlet from my swing interface.I want to send two parameters(userid and password) from swing interface(it is a login dialog box) to my servlet.Iam using Tomcat server4.0 and I also put entry of my servlet in web.xml file.Can any one plz guide me how I can slove this problem.
Below r my codes:-
Swing Interface(Iam pasting only action event of my submit button):-
================
public URL u;
public URLConnection uc;
submit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String userid1;
String password1;
String Content;
String url="http://127.0.0.1:8080/examples/servlet/loginServlet";
userid1 = userid.getText();
password1 = password.getText();
System.out.println(userid1);
System.out.println(password1);
Content= userid1 + password1;
try{
u = new URL(url+"?name=" +userid1 + "&path=" + password1);
uc =u.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
printout = new DataOutputStream(uc.getOutputStream ());
printout.writeBytes(Content);
printout.flush();
printout.close();
}catch(Exception ex){System.out.println("Error from actionPerformed :" + ex.getMessage());}
}
});
Servlet file:-
=============
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class loginServlet extends HttpServlet
{

public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
String str1=req.getParameter("name");
String str2=req.getParameter("path");
/*DataInputStream dis;
dis = new DataInputStream(req.getInputStream());
String str = dis.readLine();*/
System.out.println(str1);
System.out.println(str2);
}

}
Regards
Bikash
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with swing-servlet communication??