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

getParameter() in JSP always returns null...why?

 
Ayman Jaffar
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How come
<%= request.getParameter("testParam") %>
always return null, this is my code:
<HTML>
<HEAD>
<TITLE>JSP ExpressionsZZZZ</TITLE>
</HEAD>
<BODY>
<H2>JSP Expressions</H2>
<UL>
<LI>Current time: <%= new java.util.Date() %>
<LI>Your hostname: <%= request.getRemoteHost() %>
<LI>Your session ID: <%= session.getId() %>
<LI>The <CODE>testParam</CODE> form parameter:
<%= request.getParameter("testParam") %>
</UL>
</BODY>
</HTML>

thanks.
 
sim sim
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the element by name 'testParam' and where are u setting its value ?
Sim Sim
 
Sridhar M Swaminathan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
Well..before using the variable u should declare it.
it should be <DataType> <varName> = request.getParameter("..");
then u can access <varName> in your jsp page...
Hope this will help
- Sridhar
 
Ayman Jaffar
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm actually reading a ref. book by marty hall. I still don't know were to define the parameter ?
Could you be more specific please.
Is it possible to embed the parameter definition, instead of create a text item and etc...
thanks.
[ June 26, 2002: Message edited by: Ayman Jaffar ]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each request may (or may not) contain a 'querystring'.

This request doesn't:
http://www.foo.com/mypage.jsp

This request does:
http://www.foo.com/mypage.jsp?testParam=Hi%20There

So what would happen if you used the first URL to view your jsp page? When you try to retrieve the value of testParam from the querystring (by calling request.getParameter() ), you will get 'null' printed out. This is only appropriate, since you didn't send a querystring containing that parameter.

There is no real way to 'fake' a request parameter (ie: you can't declare it as a variable in your JSP, and then expect request.getParameter to find it). But for 'quick and dirty', you can make it a hidden field in the form that submits to the jsp in question.
[ June 26, 2002: Message edited by: Mike Curwen ]
 
Ayman Jaffar
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this reply, it helped alot, but why won't the following work when added to the same jsp file ?


ayman.
[ June 29, 2002: Message edited by: Ayman Jaffar ]
 
sim sim
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey dude , U r working with html and not xml so just remove that '/' before closing the input tag. That might help
Sim Sim.
 
Dave Comeau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it's valid XHTML. Most web browsers don't have a problem with it, although there should be a space before the />
I wite all my HTML as XHTML.
Check out http://www.w3schools.com/tags/tag_input.asp
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you on a HTML/JSP/... have:

Then on 'page2.jsp' you can use:

to get the value of 'testParam'
/Rene
[ July 01, 2002: Message edited by: Rene Larsen ]
 
Ayman Jaffar
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot guys.
I just saw this post, and wow, thanks for the replies.

[ July 01, 2002: Message edited by: Ayman Jaffar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic