Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

RequestDispatcher

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
r u having any problems in executing it ?
 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would like to knwo if it is correct in syntax.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic