Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking for none existing Attribute

 
Steve Dyke
Ranch Hand
Posts: 1643
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: 1643
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Works great!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic