Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:11:40+00:00 2026-06-13T18:11:40+00:00

I have problem with RequestDispatcher in Java Servlet, it didn’t forward to the specific

  • 0

I have problem with RequestDispatcher in Java Servlet, it didn’t forward to the specific url if the servlet path is not in root path

 protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String userPath=request.getServletPath();
    String view = null;

    if(userPath.equals("/admin")) //it's okay, forwarded
    {
            view="admin";
    }
    else if(userPath.equals("/admin/tambahArtikel")) //it's not forwarded
    {
        view="tambahArtikel";
    }
    else if(userPath.equals("/kategori")) //it's okay, forwarded
    {
        view="kategori";
    }
    String url="WEB-INF/view/"+ view +".jsp";

   request.getRequestDispatcher(url).forward(request, response);
}

and this is my web.xml

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
    <servlet-name>ServletController</servlet-name>
    <servlet-class>com.agung.webhakakses.servlet.ServletController</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ServletController</servlet-name>
    <url-pattern>/admin</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>ServletController</servlet-name>
    <url-pattern>/admin/tambahArtikel</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>ServletController</servlet-name>
    <url-pattern>/kategori</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

i think the problem is in the path but i’m not sure

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:11:41+00:00Added an answer on June 13, 2026 at 6:11 pm

    From the ServletRequest#getRequestDispatcher javadoc:

    The pathname specified may be relative, although it cannot extend
    outside the current servlet context. If the path begins with a “/” it
    is interpreted as relative to the current context root. This method
    returns null if the servlet container cannot return a
    RequestDispatcher.

    In your code, you build the url this way:

    String url="WEB-INF/view/"+ view +".jsp";
    

    So, as the javadoc also says:

    The difference between this method and
    ServletContext#getRequestDispatcher is that this method can take a
    relative path.

    So if your request URI is "/admin/tambahArtikel" and your forwarding URI does not start with a "/" then it will be relative, so the forward is sended to "/admin/" + "WEB-INF/view/"+ view +".jsp"

    If you need to forward to a resource in the WEB-INF directory start your URI with a “/” so the path will be relative to the context root.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with UIWebView delay when the load image from url. In my
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have problem with context menu. I have got: @Override public void onCreateContextMenu(ContextMenu menu,
I have problem in my xampp server php file not work if I write
My situation is: I have a servlet which should not be accessible by unauthentified
i have problem concerning to XML and java.util.List. In my script Iam able to
I have problem trying to make for each loop in C++. I'm not certain
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.