requestdispatcher problem
[nobr]Anyone have any idea whats going on over here? I am trying to use the requestdispatcher command in the servlet to forward the request to another servlet if the user name and password are good. if not then login failed error occurs.
Here is my code for CheckLoginServlet
package chapter3;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
publicclass CheckLoginServletextends HttpServlet{
privatevoid sendLoginForm(HttpServletResponse response,
boolean withErrorMessage)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Login</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
if (withErrorMessage)
out.println("Login failed. Please try again.<BR>");
out.println("<BR>");
out.println("<BR>Please enter your user name and password.");
out.println("<BR><FORM METHOD=POST>");
out.println("<BR>User Name: <INPUT TYPE=TEXT NAME=userName>");
out.println("<BR>Password: <INPUT TYPE=PASSWORD NAME=password>");
out.println("<BR><INPUT TYPE=SUBMIT VALUE=Submit>");
out.println("</FORM>");
out.println("</BODY>");
out.println("</HTML>");
}
publicvoid doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
sendLoginForm(response,false);
}
publicvoid doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
String userName = request.getParameter("userName");
String password = request.getParameter("password");
if (userName!=null && password!=null &&
userName.equals("jamesb") && password.equals("007")){
RequestDispatcher rd = request.getRequestDispatcher("/servlet/WelcomeServlet");
rd.forward(request, response);
}
else{
sendLoginForm(response,true);
}
}
}
Now here is my WelcomeServlet code.
package chapter3;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
publicclass WelcomeServletextends HttpServlet{
publicvoid doPost(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Welcome</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<P>Welcome to the Bulbul's and Boni's Web Site.</P>");
out.println("</BODY>");
out.println("</HTML>");
}
}
My CheckLoginServlet and welcome servlet is in this directory
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\myApp\WEB-INF\classes\chapter3
What is going on why is it not forwarding my request to the wellcome servlet? did i type something wrong while specifying the path in the requestdispatcher?
Thanks[/nobr]

