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?

BalusCa at 2007-7-12 14:49:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
yes sir, after handling the values
hardcodera at 2007-7-12 14:49:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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();

}

}

}

hardcodera at 2007-7-12 14:49:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
how do i use the HttpServletResponse#setAttribute()?if i have a HttpServletResponse response, do i do it like this: response.setAttribute()?i am having an error with the one above.. please help me..
hardcodera at 2007-7-12 14:49:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Ignore it, I was thinking in the wrong context. Need more coffee.
BalusCa at 2007-7-12 14:49:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...