• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Application to Serlvet Problem.  RSS feed

 
Darren Jackson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a very basic servlet for testing that returns a name.

I have made it over complicted on purpose so that in order for the servlet to work correctly it calls a method that needs a String value entered into it (which is what it should return).

Here is the Servlet:



My problem is how do I wirte the Java application side of things to send the String yourName to the servlet in the first place?

I think I am just confused right now as nothing is making any sence to me.

Here is the method I have written that I want to use to send the String, but I just have no idea how I get it to enter it???



Please help me (or let me know if you do not understand what I am trying to do).

Darren
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a first cut at a client, I'd go with something like

URL url = new URL("http://.../NewServlet?yourName=foobar");
String response = (String) url.getContent();

If you need more flexibility, have a look at the Jakarta Commons HttpCLient library. A complete client program using it can be found here.
 
Darren Jackson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to be a pain, but where exactly do I need to put those lines of code?

Ive had a look at that adition link you sent and it looks good.

I assume it is possible to send variables to and from Java App to Servlet using just the normal Servlet API though?

Darren
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Darren Jackson:

I assume it is possible to send variables to and from Java App to Servlet using just the normal Servlet API though?


What "normal" Servlet API are you referring to?

You seem to have a fundamental misunderstanding regarding the nature of servlets.

They are designed to respond to HTTP requests where data is passed as parameters on the request.

In the case of a GET, the parameters are part of the query string as in Ulf's example. In a POST, they are encoded in the request body.
 
Darren Jackson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry that did not make much sence.

I mean on a Java servlet, forget the word normal.

All I was asking is that it is possible to send and recieve variables on a serlvet?

I am very confused about the whole servlet thing currently yes.

They are designed to respond to HTTP requests where data is passed as parameters on the request.


This is the bit I am having the problems with, actually sending the parameters to the servlet.
 
Darren Jackson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I might have got the hang of it now.

I have just been playing with it and I can now get the MIDlet to pass a String to the servlet that it then outputs.

Thank you all for you help.

Hopefully one day Ill be clever at this too so I can help silly people like myself hehe.

Darren
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!