[EMAIL PROTECTED] wrote:
> Hi all,
>
> I want to forward a request from one servlet to another, but I want to
> change the remote user in the calling servlet, something like this
>
> doGet(HttpServletRequest req, HttpServletResponse) {
> RequestDispatcher rd = req.getRequestDispatcher("url to next
> servlet");
> req.setRemoteUser("newuser");
> rd.forward(req,res);
> }
>
> Of course the setRemoteUser does not exist, any ideas how I can do this?
>
For security reasons, only the servlet container can set the values returned
by methods like getRemoteUser(). Otherwise, an unscrupulous servlet author
could trick other servlets into displaying information they should not.
For your purposes, the easiest thing to do is set a request attribute instead:
RequestDispatcher rd = ...
req.setAttribute("username", "newuser");
rd.forward(req, res);
and read it in the second servlet:
String username =
(String) req.getAttribute("username");
> Pablo
>
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html