tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Stone <cityli...@petmystone.com>
Subject RequestDispatcher anomolies (Tomcat v4.1.24)
Date Mon, 16 Jun 2003 18:55:35 GMT
List,

I'm having some trouble with using a RequestDispatcher, it works and 
doesn't work.

#doPost( req, res )

...
50 Customer customer =
51     Customer.findCustomer( emailAddress, custData);
52
53     if(( customer == null ) ||
54        ( password == null ) ||
55        ( !password.equals( customer.getPassword() ))) {
56        System.out.println( "one" );
57        gotoPage( "/move/accounts.jsp", request, response );
58        System.out.println( "four" );
59     }
60
61     customer.setStartDate( request.getParameter( "startDate" ) );
     ...
69     // branching code for other forwards
70     HttpSession session = request.getSession( true );
71
72     session.setAttribute( "customer", customer );
73     if( request.getParameter( "rooms" ) != null ) {
74         gotoPage( "/move/roomCount.jsp", request, response );
75     } else if( request.getParameter( "floors" ) != null ) {
76         gotoPage( "/move/floorCount.jsp", request, response );
77     } ...

#gotoPage( url, req, res )

private void gotoPage( String address,
                        HttpServletRequest request,
                        HttpServletResponse response )
         throws ServletException, IOException {
     RequestDispatcher dispatcher =
         getServletContext().getRequestDispatcher( address );
     System.out.println( "two" );
     dispatcher.forward( request, response );
     System.out.println( "three" );
}

Basically, the idea is if the user forgets to enter a username or 
password, the servlet should forward--via gotoPage( url, req, res )-- to 
accounts.jsp. This blows up with a NPE at line 61 everytime (the lookup 
for the customer returns null, so the NPE is expected). Looking at 
standard out I see:

one
two
three
four

This shows that the test for null passed and the call to gotoPage worked 
as expected but passed through and continued to process the page, null 
reference be damned.

Yet, if the user correctly completes the form, all is fine and the 
dispatcher created in gotoPage works as expected. Standard out looks like:

one
two


What am I doing wrong that the dispatcher does not like in the first 
instance? "/travel/accounts.jsp" is available.

TIA,
Tim

PS: for those paying attention this code is loosely based on work by 
Marty Hall in /More Servlets and JavaServer Pages/


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message