wood burning stoves 2.0*
The moose likes Struts and the fly likes How to send Key/Value pair bak to Servlet from Struts?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to send Key/Value pair bak to Servlet from Struts??" Watch "How to send Key/Value pair bak to Servlet from Struts??" New topic
Author

How to send Key/Value pair bak to Servlet from Struts??

Shridhar. Blr.
Ranch Hand

Joined: Nov 23, 2000
Posts: 45
Hi All,

I have an application where in, i pass request to Struts from a Servlet.

http://localhost/struts/testAction.do?name=Shridhar&age=22.

In my Struts Action class, i take these values , hit the DB and get some other values from the DB, Now i wanna send back the data to the Client Servlet as Key/Value pairs.

return String to Client Servlet :

qualification=B.E.&specialisation=Mechanical

so that the Client can access the values thru request Object.

String qualification = request.getParameter("qualification");
String specialisation= request.getParameter("specialisation");

How do i do this.

As of now i am passing/accessing the values thru BufferedStream, i want to avoid that and send the values bak as Key/Value pairs..

Any help would be highly appreciated..

Thanks in Advance..
~Shridhar..
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Welcome to JavaRanch "Shridhar..",
We don't have a lot of rules around here. In fact, the one big rule is "Be nice." But there's another one that requires you to use a display name that is either your real name or looks like a real name. Remember the naming policy that you read when you registered?
Please take a minute to change your display name to show two names, preferably real names. It's all about maintaining our professional image--don't let the one-eyed moose fool you!
See ya around!
---
Now about your question, you can't add parameters to the request but you can add attributes (see getAttribute() and setAttribute()).


Junilu - [How to Ask Questions] [How to Answer Questions]
Shridhar. Blr.
Ranch Hand

Joined: Nov 23, 2000
Posts: 45
Hi Junilu Lacar,
Thanks for your reply.
Shridhar is my Real Name, ( my First Name..)
As U said, we can setAttribute(), If i am not wrong , setAttribute() will work only with RequestDispatcher object . I cannot use RequestDispatcher object because, my applications talks to 2 other Applications , which are hosted on 2 different machines.
so i want to send back the response to the calling Servlet (Client) as a key/value pair so that the client can get the values using request object..
Is there any other way by which i can send the values as key/value pairs..
Any help would be highly appreciated..
Thanks in Advance..
~Shridhar..
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Shridhar,
Sorry for not being very clear the first time but our naming policy requires your publicly displayed name to have at least two parts: a first name separated by a space from a second name. We understand that in some cultures people might go by just one name which is why we also allow you to use any name that is not obviously fictitious. We think it's not too much to ask our visitors and we hope that you will be gracious enough to comply.
---
Coming back to your question, when you say "my application talks to 2 other applications" do you mean that your Struts application is running on a different server than the client servlet(s)? If this is the case, the only way I can see you achieving what you want is to have your Struts action return a response which is just plain text and have your client servlet parse the response accordingly.
There might be other solutions I am not aware of that somebody else can suggest.
Shridhar. Blr.
Ranch Hand

Joined: Nov 23, 2000
Posts: 45
Hi Junilu Lacar,
You are exactly right, all the 3 are hosted on different Application servers..
As of now i am doing the same thing, i am sending text bak to the client which will parse the return value and proceed.
Anyways Thanks for Ur help..
~Shridhar..
 
 
subject: How to send Key/Value pair bak to Servlet from Struts??
 
Similar Threads
File IO with Servlet
TypeCast from String to HashMap
java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint
struts examples using mysql like loginscreen
array of sub Sets from parent Set ?