• 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

One Simple Query ??

 
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,
I want to send userId and password from my swing Interface to my servlet as just like as we send it from html file,therefore iam sending those parameter to my servlet as query string with the url.For that In swing Interface in the action event of submit button:-
public URL u;
public URLConnection uc;
submit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String userid1;
String password1;
String
url="http://127.0.0.1:8080/examples/servlet/loginServlet";
userid1 = userid.getText();
password1 = password.getText();
u = new URL(url+"?name=" +userid1 + "&path=" + password1);
uc =u.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
//Then what should I do
And In servlet:-
==============
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");
System.out.println(str1);
System.out.println(str2);
}
Is it work?Plz Guide me Iam really confused what should I do.
Regards
Bikash
[ January 29, 2003: Message edited by: Bikash Paul ]
 
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try this out? Is it working or do you face any problems? If you are facing any problems, tell us in particular.
thanks
Sudharsan
 
Bikash Paul
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,
yes I already tried with it but it is not connecting with servlet means servlet is not writing its system.out.println statement.Plz help me .Iam a beginner.
Regards
Bikash
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In debugging servlets you need to try to test the parts separately. Why not make a plain HTML page with a form that does a GET to submit the name and path to the servlet. Use that to get the servlet working, then tackle getting the swing interface working.
Bill
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bikash,
Try typing the URL you are trying to construct in the browser window and see whats happening. Make sure your URL construction is proper.
sudharsan
[ January 29, 2003: Message edited by: Sudharsan G'rajan ]
 
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could be wrong, but I believe the problem is that the Servlet/Servlet Engine expects any communication to be HTTP-based. Are you sending the proper HTTP commands? I don't see anywhere that you sent a "GET" command. You can't just connect to the URL, you have to send it HTTP commands, just like a browser does.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is not needed! If the Servlet Engine gets a request, the default method that will be executed is the 'GET' method. So, the doGet method of the Servlet will be invoked automatically. You can test this with a simple code.
 
Bikash Paul
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,
Thanks for all of ur's help.I have sloved my problem.Now my swing interface is connecting with my servlet.
Thanks
Bikash
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it gets a REQUEST. But NOT if you just open a socket to it. You have to actually SAY something to it. And the only language it speaks is HTTP. Did you try opening a socket to a servlet? See what happens.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob,
Try this code. It opens a connection with the HelloWorldServlet example that comes with Tomcat container. I have not specified any connection type.

Bikash,
How did you solve your problem?
-Sudharsan
 
Bikash Paul
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 Sudharsan,
I am not completing the cycle thats why my servlet not getting the parameter which iam sending as a query string with the url.Sudharsan can u plz tell me how u post ur above code in small font size & systematic way.Anyway Below r my modified codes:-
submit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
URL u;
URLConnection uc;
String url="http://127.0.0.1:8080/examples/servlet/loginServlet";
u = new URL(url + "?name=" +URLEncoder.encode(userid.getText()) + "&path=" +URLEncoder.encode(password.getText()));
uc =u.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
BufferedReader inputFromServlet = new BufferedReader(new InputStreamReader(uc.getInputStream()));
....
......
Regards
Bikash
[ January 30, 2003: Message edited by: Bikash Paul ]
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bikash!
When u create a post, you could find see some buttons (like URL, EMAIL, CODE, QUOTE, BOLD, etc.,) below the TextArea for entering the post. If you click on the 'code' button, it will insert the code tags. Enter the code you want to post within those tags.
sudharsan
 
Bikash Paul
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 sudharsan,
Thanks for ur help.
Regards
Bikash
[ February 02, 2003: Message edited by: Bikash Paul ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic