I am using Servlets and JSP. I am trying to delete some order from my web app. Servlets version 3.0, servlet container Tomcat v.7.65.
Part of my web.xml
:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>InitController</servlet-name>
<servlet-class>com.taxi.service.controller.InitController</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>OrderController</servlet-name>
<servlet-class>com.taxi.service.controller.OrderController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InitController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>OrderController</servlet-name>
<url-pattern>/createNewOrder</url-pattern>
<url-pattern>/deleteOrderFromAdmin/*</url-pattern>
<url-pattern>/editOrderFromAdmin/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
I am trying to delete order and in my jsp i use:
<td><a href="<c:url value='/deleteOrderFromAdmin/${order.id}' />">Delete</a></td>
But when i am trying to add special mapping /deleteOrderFromAdmin/* , i am getting an error (i know that my InitController creates this issue because it mapped for "/"):
javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:326)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
at com.taxi.service.controller.InitController.doGet(InitController.java:33)
My InitController must be loaded on startup because it contains many options for my services and so for other web-services from my app.
In my Order delete method i am using some kind of path interpritation like this:
Long orderId = null;
String[] pathParts = request.getPathInfo().split("/");
if(pathParts != null && StringUtils.isNoneEmpty(pathParts[1])){
orderId = Long.parseLong(pathParts[1]);
}
if (orderId != null) {
orderService.deleteOrder(orderId);
}
I must to take this order id and must to delete it.
Question: How to solve that problem with mapping?
Thanks.
Update:
All those mapping changes ("/*") are starting from my needs to get that order id from my jsp page. Is there some alternative way to made such thing to get those id from jsp?