• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

servletcontext.getRequestDispatcher(resource) throwing IllegalArgumentException

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

Your syntax will like this...



 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys...It helped
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can try this code

RequestDispatcher rd=getServletContext.getRequestDispatcher("input.jsp");
rd.forward(request,response);
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic