1

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?

Alexey Shabramov
  • 730
  • 1
  • 16
  • 37
  • 1
    show the complete stack trace, and also `doGet` method in InitController – Sajan Chandran Oct 14 '15 at 14:00
  • 1
    Wich Servlet version are you using ? You might need to reorder your mappings so that `InitController` is the last if you want your request to go to the right controller. By the way, why do you need the `/*` in your mappings ? – Gaël J Oct 14 '15 at 14:00
  • I am using Servlets 3.0. This mapping "/*" appeared when i were trying to get Order id from my Jsp page by using button with special url: .Unfortunately i didn't know alternative to solve this thing without affecting servlet mapping. – Alexey Shabramov Oct 14 '15 at 14:04
  • 1
    Mapping application-specific servlets on `/*` or `/` is Bad Practice. The `/*` should be used for filters only and the `/` should be used for global front controller servlets only who are also capable of dealing with static resources. Food for read (and likely also a duplicate): http://stackoverflow.com/q/4140448 – BalusC Oct 14 '15 at 15:17
  • Hi BalusC, i read much info from your answers and must to say Thanks for all your work in here. The reason i asked that question: i am trying to get order id from my jsp page, and i started to make such things with mapping (in Spring i had no problems with it, but in servlets, i need to find some way to get id without mapping changing). – Alexey Shabramov Oct 14 '15 at 15:26

0 Answers0