• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting null value for request.getParameter()  RSS feed

 
Charisse Lane
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a null back from the following code:

public String getUserName(HttpServletRequest request)
throws RemoteDataException
{
String userName = request.getParameter("sm_user");
if(userName == null)
userName = request.getRemoteUser();
LOG.debug("Getting " + userName + " from the charisse request");
return userName;
}


I passed the value "sm_user" from the following JSP that calls the above servlet code. The "sm_user" variable contains a valid user ID.


<input type="hidden" value="<%=attVal%>" name="sm_user" />
<SCRIPT type="text/javascript">
document.postform.submit();
</SCRIPT>


I think this is happening because the getParameter doesn't work with the HttpServletRequest object but maybe only works with the ServletRequest object.

Can I just change the above code from:

public String getUserName(HttpServletRequest request)

to


public String getUserName(ServletRequest request)



I'm not sure if this will break something else.

Here's the error from the log file:

[2009-04-08 12:29:58,547][DEBUG][com.vignette.tas.util.HttpUserNameCallback] - Getting null from the charisse request



 
Charisse Lane
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed it and now request.getRemoteUser() doesn't work because it's part of the HttpServletRequest class.

ugggh!

Anyway, I'm not sure if I need this code so I'm going to comment it out.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I think this is happening because the getParameter doesn't work with the HttpServletRequest object but maybe only works with the ServletRequest object.


getParameter() is indeed method of ServletRequest and HttpServletRequest extends it , and does not has its ow


I passed the value "sm_user" from the following JSP that calls the above servlet code. The "sm_user" variable contains a valid user ID.


how are you sure about it.
 
Charisse Lane
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I'm getting a compile error:

[javac] C:\projects\MyCSP_CMS\Code\src\com\vignette\tas\util\HttpUserNameCal
lback.java:16: com.vignette.tas.util.HttpUserNameCallback should be declared abs
tract; it does not define getUserName(javax.servlet.http.HttpServletRequest) in
com.vignette.tas.util.HttpUserNameCallback


Not sure what this means.

To answer your question about how I'm sure that I'm actually posting a value, I created a different jsp called showcookievalue.jsp that actually shows the value of the hidden variable. This is another jsp however and not a servlet.

I have the following code in the showcookievalue.jsp and it displays the value:

out.println("<p>username: " + request.getParameter("sm_user"));

Again, this is a JSP so the request.getParameter actually works.
 
Charisse Lane
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason, although passing the parameter works from JSP page to a different page, it doesn't seem to be passing it to the Servlet in question.

I'm just going to take a different approach and retrieve the value directly within the needed class.


Thanks for your help!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!