File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher

 
Lucky Singh
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
{
rd.forward(req,res);
}
}
else
{
//Return to LoginPage.
RequestDispather rd2 = getServletContext().getRequestDispatcher("/Login.jsp");
rd2.forward(req,res);
}
}//end doGet.
}//end Login.
[ March 24, 2004: Message edited by: Lucky Singh ]
 
Kaustubh Patil
Ranch Hand
Posts: 164
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
r u having any problems in executing it ?
 
Lucky Singh
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would like to knwo if it is correct in syntax.
 
Kate Head
Ranch Hand
Posts: 67
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Kate!!
[ March 24, 2004: Message edited by: Kate Head ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic