respose.sendRedirect(URL) Vs RequestDispatcher
if i use respose.sendRedirect(URL) and use request.setAttribute all my variable values are erased. but if i use RequestDispatcher, my page is like in a different directory and messes up all the links for css.. how do you go about this? do you have any solutions for this? and if i am going to use session.setAttribute how when and where do i remove the session values? thanks
[382 byte] By [
hardcodera] at [2007-11-27 5:27:43]

# 1
> if i use respose.sendRedirect(URL) and use request.setAttribute all my
> variable values are erased.
Use HttpServletResponse#setAttribute() instead.
> but if i use RequestDispatcher, my page is like in a different directory and
> messes up all the links for css.. how do you go about this? do you have
> any solutions for this?
Define a base href and start all relative links with "/" (indicating the root). Or use absolute links instead.
> and if i am going to use session.setAttribute how when and where do i
> remove the session values? thanks
After handling the values?
# 3
what do you mean by
> Use HttpServletResponse#setAttribute() instead.
i have a piece of code that looks like this. is this what you meant?
private void processRequest(HttpServletRequest request, HttpServletResponse response) {
Connection con = null;
HttpSession session = request.getSession();
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username.trim().equals("") || password.trim().equals("")) {
errors = "Invalid USERNAME or PASSWORD.";
try {
session.setAttribute("errors", errors);
//request.setAttribute("errors", errors);
response.setAttribute();
session.setAttribute("username", username);
response.sendRedirect("../login.jsp");
} catch (IOException e) {
e.printStackTrace();
}
}
}