It's not a secret anymore!*
The moose likes Servlets and the fly likes Servet parameters not receiving prolbem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Servet parameters not receiving prolbem" Watch "Servet parameters not receiving prolbem" New topic
Author

Servet parameters not receiving prolbem

balal subramanianl
Greenhorn

Joined: Feb 11, 2004
Posts: 2
I am receving some functioncode from my servlet request//
like http://myservlet:8022/MyServlet?F=TET_FUN_DJF
After I am checking the following checks.Because request contains..
F or F_NUM or F_ANA.
for ex:
functionParamName1=F
functionParamName2=F_NUM
functionParamName3=F_ANA
String fun_cod = request.getParameter(functionParamName1);
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName1.toLowerCase());
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName2);
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName2.toLowerCase());
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName3);
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName3.toLowerCase());
if (fun_cod == null) {
throw new MyException(request,"The request does not have a function code");

But some sceanerios the fun_code not getting prperly..so its going to exception at this time..
Any body have any idea about this...
I checked the WebServer request logs...because its having at this time.
only http://myservlet:8022/MyServlet
please provide some idea about this...

Bala L
Owee Nicolas
Ranch Hand

Joined: Jun 16, 2002
Posts: 49
Hi Balal,
Let me see if I got your message right, you are passing the value of parameter F on your Query String. On your servlet code, you are checking if the parameter passed is the parameter F since you mentioned that you also have other parameters like F_NUM and F_ANA.
Now your question is how come you're getting an exception even if you had a series of conditions checking if the value of parameter F was passed to the fun_cod String variable. If the parameter F was not passed (or if the fun_cod was null) then you assign fun_cod with the parameter of F_NUM then F_ANA.
I think the request.getParameter() method is retrieving the wrong parameter. Try hard coding the name of the parameter on the request.getParameter() method like: request.getParameter("F");. Also, make sure that you are inside the doGet() method of the Servlet.
It might help if you paste your exact code here so the ranchers can take a look.
Hope this helps!


Owee<br />SCJP 1.4
balal subramanianl
Greenhorn

Joined: Feb 11, 2004
Posts: 2
Hi,
Thanks.First I am reading this xml and store the value..
this is the exact process...
<Property Name="functionNameParameter1" Value="FUN_NAM"/>
<Property Name="functionNameParameter2" Value="FUNCTION"/>
<Property Name="functionNameParameter3" Value="F"/>
then I check in the servlet in the every request
like this...in doGet method...
String fun_cod = request.getParameter(functionParamName1);
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName1.toLowerCase());
if(fun_cod == null)
fun_cod = request.getParameter(functionParamName2);
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName2.toLowerCase());
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName3);
if (fun_cod == null)
fun_cod = request.getParameter(functionParamName3.toLowerCase());
if (fun_cod == null) {
//Something wrong with the request, no function param specified!!!
MyException( "The request does not have a function code, so discarding the"));

My doubt is this is why some times coming this...
whether any browser behaves like this..or in the heavy load,parameter not coming...
and hidden parameters from jsp (fun_cod) not coming properly...
Because F for the first request,then FUN_NAM from the jsp and ..
Thanks
Bala...
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

It's a bit hard to interpret your meaning (you have a bad habit of not finishing sentences...)

What I think is: Your servlet requires ONE of the following parameters to have a non-null value...
F, f, F_NUM, f_num, F_ANA, f_ana

At least ONE of these parameters must contain a value, or the request is considered 'faulty'.

How about only checking for the one case (F, F_NUM and F_ANA) ? There is no reason for your users specifying their own parameter names. You (or a person on your team) as the JSP page developer or the person creating the HTML FORM should understand what parameters are required. If they are missing, then this is a good reason to throw an 'Application' exception (as it's a problem with your JSP/HTML/servlet application, not any one users's fault). There's no reason for checking both upper and lower case.

Also, the advice about making sure you're in doGet() only applies if you are using the GET method. If it's a link click, then yes, this is doGet(), but if you have an HTML FORM with method="POST", then obviously this is doPost().

And there is an upper limit on the length of a URL. It is fairly high, but if you have many, many parameters (not to mention a jsessionid if you're supported no-cookie users), then you might be running into this limit.

http://www.coderanch.com/t/357864/Servlets/java/URLEncode-limits
 
GeeCON Prague 2014
 
subject: Servet parameters not receiving prolbem