• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

URL Writing in JSP

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Can somebody help me in rewriting this URL I'm assigning null to parameters abc and bcd but this way value null is displayed in the fields. I want to assign null string to these parameters. But when I use SCREENTO = "" my URL string gets cut at that point itself.
how should it be written
<href="abc=null&bcd=null&SCREENTO=""&INITIAL=YES">Search</a>
Can somebody help.
Thanks
Neha
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Leave out abc, bcd and SCREENTO:
<href="INITIAL=YES">Search</a>
the getParameter() will return null for those param names.
You example is missing code and I played along...
[This message has been edited by Tony Alicea (edited October 03, 2001).]
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying Tony
If you don't pass any parameter and you do a request.getParameter then you get a nullpointer exception so to save that I need to pass a parameter.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neha,
Tony is correct. Your getParameter call should not be throwing a NullPointerException. It's probably something else. Can you post the code that is generating the NullPointerException?
------------------
Miftah Khan
- Sun Certified Programmer for the Java� 2 Platform
- Sun Certified Web Component Developer for the Java� 2 Platform, Enterprise Edition
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
neha,
everyone is right ur getParameter() returns null if the object of that name is not on the html..
the null pointer exception may be because ur request object might be null..
just find it out.
Kaustubh
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know what you guys are talking about but if I take away a single parameter from my URL I get this exception in my servlet.
[01.10.05 14:02:53:337 EDT] 5ac0f740 WebGroup X Servlet Error: : java.lang.NullPointerException
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
neha,
why don't you post your code which you think throws the exception.
meanwhile try this -
<href="abc=&bcd=&SCREENTO=""&INITIAL=YES">Search</a>
this way you will get an empty string as the value instead of null when you do req.getParameter("abc")
ofcourse, i don't know what SCREENTO is.
[This message has been edited by shilpa kulkarni (edited October 05, 2001).]
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could have posted my code but it's too big and it references some DAOs and EJBs so basically you won't be able to run it or understand it. right now I'm running it passing the parameters as hidden fields. But I'm not happy the way I'm doing it. But for my application I'm 100% sure it is giving me problems if I don't pass the parameters. I don't know if it is application server specific or any other thing.
Thanks
Neha
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've got two requirements:
1) I need to pass each parameter for my app to work.
2) I need some parameters to be null sometimes.
These two requirements are mutually exclusive.
You need to fix your app so that it can handle null parameters. You can never guarantee that a user will behave himself... for instance, even if you have some client-side validation, a naughty user can modify the page on his side and get around your client-side stuff.
So before you ever attempt to use a parameter, test to see if it's null first. Then you won't get a nullpointer exception. If you absolutely needed that parameter for something, and it's tests null, then send the user off to an error page.
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Dave thanks for your answer but my problem is in my servlet when I say
if request.getParameter("abcd").equals(null) {
do this
} else {
do that
}
and I'm not passing the 'abcd' parameter from my calling jsp I get this nullpointer exception. Once I just pass this parameter in my URL (may it be null). I get no error.
Thanks
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
while writing my last message itself I realized 'equals' doesn't work if you compare nulls. It's working without parameter passing if I'm using '!='
Thanks
Neha
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok to settle this once and for all
when u use the .equals("") method it gets the value stored inside the string itself and tries to compare it to the string u pass to the .equals("") method.
so guys if u don't pass a string in the url request then
calling the .equals method on the string will ofcourse give the nullPointerException because the string isn't there in the first place.
to put it into code the string parameter you're trying to access is pointing to null and not any value in the memory.
therefore u should check like this if the parameter is forexample called "abc" :
if ( abc == null )
i hope its clear now.
------------------
KaReEm
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kareem
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Request Object is very dynamic in a sense
 
pie. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic