• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking for none existing Attribute

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have one sevvlet that is called by two different JSP's. The first JSP has a form with two named attributes that it sends as parameters. The second JSP does not have any named attributes to send along. How can I set the servlet code to accept either.

My servlet code:

 
Jenn Person
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm certain there is a more elegant solution, but I would just test the incoming paramater to see if it's null or not.

if (request.getParameter("my_parameter") != null)
{
//do something
}
else
{
//do something else
}
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Works great!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic