Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about request.getParameter().

 
james gong
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginer of jsp.the code bellow is in my jsp file.
"<% String firstName = request.getParameter("fName");%>"
when there isn't a parameter named fName ,then a NullPointException will come out.In order to prevent this happen,I use
"<% if(request.getParameter("fName")==null)firstName="jack"%>"
the compiler complained the Syntax.
what can I do with it?
 
Raghav Sam
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by james gong:
I am a beginer of jsp.the code bellow is in my jsp file.
"<% String firstName = request.getParameter("fName");%>"
when there isn't a parameter named fName ,then a NullPointException will come out.In order to prevent this happen,I use
"<% if(request.getParameter("fName")==null)firstName="jack"%>"
the compiler complained the Syntax.
what can I do with it?

hi,
i dont see anything wrong except for a space you have to give after the 'if' check and a semicolon at the end, like,
"<% if(request.getParameter("fName")==null) firstName="jack"; %>"

raghav.
 
abhay rege
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Games,
Tell me what syntax error you got.As seen your there is a semicolen missing at the end of statement.
Your code was :
"<% if(request.getParameter("fName")==null)firstName="jack"%>"
I suggest:
"<% if(request.getParameter("fName").equals(null))
firstName="jack";%>"
Use equals method instead of == incase of comparison of two strings because strings are immutable in java.
Give me your feedback.
Regards
Abhay
 
Raveendran Karunakaran
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

what error message did you get ? tell me that and then i will tell you what can be done to rectify it.

awaiting your reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic