aspose file tools*
The moose likes Servlets and the fly likes question about request.getParameter(). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "question about request.getParameter()." Watch "question about request.getParameter()." New topic
Author

question about request.getParameter().

james gong
Ranch Hand

Joined: May 29, 2001
Posts: 48
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

Joined: Apr 12, 2001
Posts: 412
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.

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.<br />- Dr. Seuss
abhay rege
Greenhorn

Joined: Jun 28, 2001
Posts: 6
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

Joined: Jun 25, 2001
Posts: 38

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about request.getParameter().