File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error passing data from jsp to servlet

 
diana b
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic