JavaサーブレットのRequestDispatcherに問題があります。サーブレットパスがルートパスにない場合、特定のURLに転送されませんでした
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);
}
これは私の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>
問題は道のりにあると思いますが、よくわかりません