• 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

Servlet 5 doPost?

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what I am missing. Thought that:

would be sufficent to get going but the pass string is null. What I am overlooking?
[ December 15, 2003: Message edited by: Greg Neef ]
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Several comments.
1. Why are you first creating a session then checking the password? I would think you'd want things the other way around: first check the password, then create the session only if the password is correct.
2. Why are you trying to get the password from the attributes of the session? That's not where the system puts it for you. (If you want to check what kinds of things *do* get stored as attributes, HttpSession.getAttributeNames() gives you an Enumeration of attribute names you can play with. (Working with an enumeration is similar to working with an iterator -- I gave an example of that just a few weeks ago.) Given your code, I'm reasonably confident your session doesn't have any attributes, but it's fun to check these things for yourself.)
3. Your cast (String)session.getAttribute( "pass" ); is a risky operation. HttpSession.getAttribute(String) only guarantees to return an Object (or null). (Yes, I know all Objects have toString(), but you're casting here and setting yourself up for a ClassCastException if the attribute is anything but a String.)
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parameters are Strings, attributes are Objects. It would behoove you to remember that when dealing with servlets. A simple enough lesson to learn, but a fact that seems to cause many a new servlet developers much consternation
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic