• Post Reply Bookmark Topic Watch Topic
  • New Topic

servletcontext.getRequestDispatcher(resource) throwing IllegalArgumentException  RSS feed

 
Shaik Muhammad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to forward a httpservletrequest to a servlet from a controller servlet. When i call the method with web.servlets.loginServlet as input parameter, this method throws IllegalArgumentException saying that the input parameter does not contain '/'. Please help.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with web.servlets.loginServlet as input parameter

It doesn't look like a path. Is it a named servlet ? If so, use getNamedDispatcher instead.
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

Your syntax will like this...



 
Ravindra Verma
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have request dispatcher object in two ways.
request.getRequestDispatcher("abc"); // #1
or
servletContext.getRequestDispatcher("/abc"); // #2

difference is when you use #1 server will look for the resource abc from current directory. In case of #2 it will start looking from context root so you need to put a '/' before your resource path. In case of #1 you may get in serious troubles sometimes you may need to put whole path like (http://localhost:8080:.........).

Regards
Ravindra
 
Shaik Muhammad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys...It helped
 
Brijesh Verma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can try this code

RequestDispatcher rd=getServletContext.getRequestDispatcher("input.jsp");
rd.forward(request,response);
 
Harmanjit Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When using request dispatcher from servlet context, the pathname must begin with a "/" and is interpreted as relative to the current context root.


Above code will cause IllegalArgumentException
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!