Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with swing-servlet communication??

 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic