Discussions

Web tier: servlets, JSP, Web frameworks: Get Servlet without mapping in web.xml

  1. Get Servlet without mapping in web.xml (2 messages)

    Hi,

    I am using WebLogic 6.1. I want to forward to a servlet from another servlet and also I do not want to have corresponding servlet-mapping entry in the web.xml. So, how can I do that ? I tried in the following way but failed (relative path of calling servlet):

    [code]....
    requestDispatcher = getServletContext().getRequestDispatcher("./xyz/AbcdServlet");
    requestDispatcher.forward(request, response);
    ....[/code]

    I also tried in the following way but failed (i.e. relative path to the root path):

    [code]....
    requestDispatcher = getServletContext().getRequestDispatcher("/xyz.abc.AbcdServlet");
    requestDispatcher.forward(request, response);
    ....[/code]

    Thanks,
    Abhijit
  2. try /servlet/xyz.AbcdServlet

    or

    /servlet/xyz/AbcdServlet

    > Hi,
    >
    > I am using WebLogic 6.1. I want to forward to a servlet from another servlet and also I do not want to have corresponding servlet-mapping entry in the web.xml. So, how can I do that ? I tried in the following way but failed (relative path of calling servlet):
    >
    > [code]....
    > requestDispatcher = getServletContext().getRequestDispatcher("./xyz/AbcdServlet");
    > requestDispatcher.forward(request, response);
    > ....[/code]
    >
    > I also tried in the following way but failed (i.e. relative path to the root path):
    >
    > [code]....
    > requestDispatcher = getServletContext().getRequestDispatcher("/xyz.abc.AbcdServlet");
    > requestDispatcher.forward(request, response);
    > ....[/code]
    >
    > Thanks,
    > Abhijit
  3. That won't work as he stated
    "...I do not want to have corresponding servlet-mapping entry in the web.xml".

    May I ask why you don't want a mapping?

    Is xyz a subdirectory located immediately below the directory containing the calling Servlet? You should be able to use:

    request.getRequestDispatcher("xyz/AbcdServlet").forward(request, response);

    Are both Servlets in xyz? You should try:

    request.getRequestDispatcher("AbcdServlet").forward(request, response);

    I wouldn't guarantee either will work. The request dispatcher is going to be based on the relative path of the calling Servlet (which is going to be http://mywebsite.com/servlet/).

    Good luck there.