Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher" Watch "RequestDispatcher" New topic


Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
Is this right?

public class Login extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
String user, pass;
boolean response = false;

user = req.getParameter("username");
pass = req.getParameter("password");

DatabaseChecker ct = (DatabaseChecker)(getServletContext().getAttribute("ct"));
response = ct.validate(user,pass);

if(response == true)
HttpSession userSession = req.getSession(true);
userSession.putValue("userName", user);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Welcome.jsp");
if (rd != null)
//Return to LoginPage.
RequestDispather rd2 = getServletContext().getRequestDispatcher("/Login.jsp");
}//end doGet.
}//end Login.
[ March 24, 2004: Message edited by: Lucky Singh ]
Kaustubh Patil
Ranch Hand

Joined: Aug 13, 2001
Posts: 164
r u having any problems in executing it ?

Kaustubh. Mumbai, India.
Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
Would like to knwo if it is correct in syntax.
Kate Head
Ranch Hand

Joined: Oct 31, 2002
Posts: 67
Hi there,
I was told to put return; after the call to rd.forward(req, resp);
I also used String nextScreen to hold the "/Welcome.jsp" or "/Login.jsp" names so used the following format:

Hope that helps.
All the best,
[ March 24, 2004: Message edited by: Kate Head ]
I agree. Here's the link:
subject: RequestDispatcher
It's not a secret anymore!