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

Problem with swing-servlet communication??

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic