Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

want to pass a string to a servlet

 
HARSHAD bhawsar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frds
I am using following code to pass a string to servlet,
<a href=**\myservlet?param=xyz>xyz</a>
It's working;
But what if i want to pass an string like "hello xyz how r u?"
It is passing only "hello", and not rest string , is there athor solution to pass it
 
Ajan Balakrishnan
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did yout try URL encoding
for example in your case your parameter value will be "hello%20xyz%20how%20r%20u?" where %20 is for space
OR
<a href=**\myservlet?param=URLEncoder.encode(hello xyz how r u)</a>
if you are using jsp. Remember to decode it while retreiving the value
I'm not sure if this is what you are looking for but worth giving a chance
AJan

[This message has been edited by Ajan Balakrishnan (edited March 10, 2001).]
 
Daniel Olson
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Ajan is right. I just wanted to add that in my experience it depended on what browser I was using. With Netscape I had to URLEncode, but not with IE. IE doesn't have trouble if you do, but it doesn't seem to care whether you do or not.
 
HARSHAD bhawsar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ajan,Danial,
I am not using Jsp.
Do you think this will work on plane servlet and tell me how to collect string in another servlet using url rewriting
Harshad
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harshad,
In the calling Servlet just wrap the address with URLEncoder.encode(...). In the called servlet you need not decode anything. Just request.getParameter(..) will do.
I tested your need with the following code. Please check.


[This message has been edited by maha anna (edited March 13, 2001).]
 
Sam Zheng
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maha,
When TestServlet receives the dispatcher from MyServlet,
which method takes care of the action, doGet(*,*) or
DoPost(*,*)? I know that in your program, you call doGet()
from doPost(), so it doesn't really matter there. But,
which method is called excatly? Can I specified GET
or POST from MyServlet to direct the method call in
TestServlet?
Thanks!
Sam
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam,
It looks like POST method is used for the dispatcher when forwarded to TestServlet. Initially I wrote only doGet(...) in TestServlet and did not get "msg" printed out at DOS command prompt. So, in order to make sure which method (GET/POST) is used, I wrote doPost(...) to call doGet(...) in TestServlet and immediately got the "msg" printed out at command prompt.
For the testing I used http://localhost/MISApp/servlet/MyServlet at the browser. Instead of "MISApp" you can use your webApplnContextName.
regds
maha anna

[This message has been edited by maha anna (edited March 15, 2001).]
 
Tom Caldwell
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone else had this problem? This is my 1st try at these but when I try to run this I get the message "No target servlet configured for uri: /app/TestServlet?msg=Hello "
This is the correct address as I can run both of these separately
by myURL/app/MyServlet or myURL/app/TestServlet. I've tried every combination of address I can think of is there something else?
I'm running websphere.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic