aspose file tools
The moose likes Servlets and the fly likes URL Writing in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "URL Writing in JSP" Watch "URL Writing in JSP" New topic
Author

URL Writing in JSP

Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
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
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3219
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).]


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
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.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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
Kaustubh Patil
Ranch Hand

Joined: Aug 13, 2001
Posts: 164
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


Kaustubh. Mumbai, India.
Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
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
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
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

Joined: Jul 13, 2001
Posts: 126
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
Dave Soto
Ranch Hand

Joined: Sep 15, 2001
Posts: 55
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

Joined: Jul 13, 2001
Posts: 126
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

Joined: Jul 13, 2001
Posts: 126
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
Kareem Gad
Ranch Hand

Joined: Aug 06, 2001
Posts: 89
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


<b><i>KaReEm</i><br /><ul type="square"><li>SCJP-Free Range Web Developer <br /></ul></b>
Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
Thanks Kareem
Ray Smilgius
Ranch Hand

Joined: Jan 29, 2001
Posts: 120
The Request Object is very dynamic in a sense


SCJO, SCJD, SCWCD, I-Net+, A+, Network+, MCSD, MCDBA, MCP, MCT
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URL Writing in JSP
 
Similar Threads
How to Group a Collection of Pojo's based on some pojo property?
help regarding EL tags
Using Character and Strings with HashSet ,LinkedHashSet,HashMap,LinkedHashMap Problem
Why null is return?
Playing with a string - need suggestions.