aspose file tools*
The moose likes Servlets and the fly likes Error passing data from jsp to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error passing data from jsp to servlet" Watch "Error passing data from jsp to servlet" New topic
Author

Error passing data from jsp to servlet

diana b
Greenhorn

Joined: Feb 02, 2001
Posts: 6
Hello,
I need to pass user id from jsp to servlet.
I am using this code in jsp:

<%
if (request.getRemoteUser() != null) { %>
<%
String userid = request.getRemoteUser();
%>
<jsp:forward page="/servlets/packageName/UserAuthorization1" >
<jsp aram name="user" value="userid" />
</jsp:forward>
%>
Inside of servlet( to retreive this user id):
String user1 = req.getParameter("user").trim().toUpperCase();
This return Null.
Could somebody tell me what is wrong and how should I correct it.

Thanks in advance
Diana
[This message has been edited by diana b (edited February 05, 2001).]
[This message has been edited by diana b (edited February 05, 2001).]
[This message has been edited by diana b (edited February 05, 2001).]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by diana b:
String user1 = req.getParameter("user").trim().toUpperCase();
This return Null.

First of all, req.getRemoteUser() works in a servlet as well. Second, req.getParameter() is to retrieve request parameters (ie the things normally tacked onto the URL), while the username is in fact a request header field. You would use req.getHeader("user") to retrieve it (note: I'm not sure "user" is the right name).
- Peter
diana b
Greenhorn

Joined: Feb 02, 2001
Posts: 6
Peter,
if I am using in a servlet
req.getHeader("user"),
should I pass inside of jsp value of parameter or
only param name, I mean:
<%
if (request.getRemoteUser() != null) { %>
<jsp:forward page=/servlets/packageName/UserAuthorization1">
<jsp param name="user" />
</jsp:forward>
} %>
Thanks
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Diana,
Are you sure about the url which you gave in forward is correct?
In one of my testings I used this. Here I forwarded to another jsp from a jsp file with a param. Please check it.
To forward to a servlet first try with full URL.

regds
maha anna
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by diana b:
Peter,
if I am using in a servlet
req.getHeader("user"),

Oops. I was talking partial nonsense. HTTP authentication is quite a bit more involved than this. You really don't want to handle it yourself and just use HttpRequest.getRemoteUser().
should I pass inside of jsp value of parameter or
only param name, I mean:
<%
if (request.getRemoteUser() != null) { %>
<jsp:forward page=/servlets/packageName/UserAuthorization1">
<jsp param name="user" />
</jsp:forward>
} %>

I'm not quite sure if I get you here. If you'd pass a parameter "user" in the forward this way (probably with a value?), that is a request parameter and you would retrieve it using req.getParameter().
On the other hand, you don't need to pass the authenticated user in this way; in the servlet, req.getRemoteUser() should work without you passing that information explicitly. After all a forward causes the original request to be forwarded as well.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error passing data from jsp to servlet