• 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

retrieving a parameter from a link

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai friends, i have a problem with retrieving a parameter from a link using HttpServletRequest object. Following is the code

String action = request.getParameter("action");
PrintWriter out = response.getWriter();
response.setContentType("text/html");
if(action != null && action.equals("invalidate"))
{
HttpSession session = request.getSession();
session.invalidate();
}
out.println("<a href=\"http://localhost:8080/servlets-examples/Session1 \""+"?action=invalidate>");

Assume that the previous out.println statement is in a single line.

But action is always assigned null value. Why request(HttpSrevletRequest object)is not able to read "action" parameter from the link i created in the servlet. Is there any thing wrong with the syntax i used in out.println statement?
thank u in advance
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know that it's always null?
Have you tried printing it or looking at the headers?

Try printing it right at the top of your service method:
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Give a name to your hyper-link in the out.println statement for eg concatenate the string in the out.println stmnt with "Click here!" so that it displays "Click here!" on the html page. Click on that and check what is displayed in the address bar.
Also, give an SOP in the pgm to check the value of the string 'action'
 
subba rai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello friends,
sorry for not making myselef very clear. I have tried to print the string object "action" and also i have given a name to my link. After clicking the link action is assigned null value but not "invalidate".
sorry for not telling these things in my code these things in my previous query. Now u can think about what may be the problem
thank u in advance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try what I suggested -- print the value at the top of your doPost or doGet method?

 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your link seems to turn out to be

<a href="http://localhost:8080/servlets-examples/Session1"?action=invalidate>

this will not send the action parameter in.

the link should be <a href="http://localhost:8080/servlets-examples/Session1?action=invalidate"/> instead.

And as Ben said, there's no place in your posted code that lets you find out whether or not action is null.
[ April 12, 2005: Message edited by: Yuriy Zilbergleyt ]
 
subba rai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank u friends...i have found out the mistake
-----------------------------------------------------------------------------
correct usage:
out.println("<a href=\"http://localhost:8080/servlets-examples/Session1?action=invalidate\">");
------------------------------------------------------------------------------
wrong usage:
out.println("<a href=\"http://localhost:8080/servlets-examples/Session1\""+"?action=invalidate>");
-------------------------------------------------------------------------------
once again thanks.....bye for now
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic