Forums Register Login

URL Writing in JSP

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Thanks Kareem
+Pie Number of slices to send: Send
The Request Object is very dynamic in a sense
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1259 times.
Similar Threads
Playing with a string - need suggestions.
Using Character and Strings with HashSet ,LinkedHashSet,HashMap,LinkedHashMap Problem
help regarding EL tags
How to Group a Collection of Pojo's based on some pojo property?
Why null is return?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:00:03.