I have problem in using RequestDispatcher.forward() from servlets. My knowledge is that even after calling this method servlet continues processing the request and thus executes rest of the service method.
Your understanding is correct -- it's just a method call that returns.
But I have seen that if a servlet is forwarding to same servlet it stops responding unable to get a database connection from pool. (I have set maxconncections to 1).
That's probably because your servlet looks like this:
try { conn = getConnection();
// process
getRequestDispatcher().forward(...); } finally { conn.close(); }
This is a recipe for trouble, because you're still holding the connection when you forward to another servlet. If that servlet tries to get a connection, you have the potential for deadlock.
Good for you for setting your connection pool size to 1! Everyone should do this, because then you have the good fortune to find things like this in development environments instead of in production, and you try to figure out why all 25 of your connections seem to be tied up :)
Database connection is closed in service method in the finally block which is coming after the forward() statement. What is wrong ?.
You said it yourself: you are retaining the connection during the method call. Finally blocks run after all the code inside it done, not when the thread leaves the method. MEthod calls within try/finally blocks don't trigger the finally block to be called. You need to modify your code thus:
try { conn = getConnection();
// process } finally { conn.close(); }
if (iShouldForward) getRequestDispatcher().forward(...); else getRequestDispatcher().redirect(...);
Another question how to remove a query string from a request before forwarding it. (Actually I have to remove a textbox element from a form.)
I'm not sure you can do this... but, you can wrap the HttpServletRequest in an implementation that *you* write that can ignore that attribute. Seems pretty hacky. Another thing you could do is put a marker object in the request attributes that says "ignore the request parameter". Your other action, that should not see the element value, can check for that marker object and then ignore the parameter value.
-chris
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]