Hi,
I have a servlet forwarding a request to another url in the same domain. I want to pass a string between the two, like:
// ServletVerifyUser.java:
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
// do some work..
req.setAttribute("message", "Thanks for signing up!");
req.getRequestDispatcher("/login.jsp").forward(req, resp);
}
// login.jsp
<%
// message is null.
String message = request.getAttribute("message");
<p><%= message %></p>
%>
Does the request object not work like this?
In my case, I am running ServletVerifyUser when a user clicks a url I generate for them after signup. At the end, I'd like to redirect them to my login page, but embed the message in the request. Then the login page can just render whatever the verify servlet prepared for it,
Thanks
------------------ Edit -------------------------
Ok so looks like the problem was that my login page is actually located at:
/login/index.jsp
on my local test machine, I was using this string for the url:
"/login"
(I tried to make the above example simpler by just showing "/login.jsp" because I didn't think this would make a difference, the url was still being resolved ok in the browser).
But when I use: "/login", the attributes are gone, if I use the full path: "/login/index.jsp", then the attributes are present.
I put the login jsp in a separate folder like this in order to keep nicer look urls, for example I can just give a user:
www.mysite.com/login
instead of:
www.mysite.com/login.jsp
but there is probably a better way to do this too (still really new with this)
Thank you