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