我有以下servlet:

@WebServlet("/publication/topic/*")
public class ViewTopicPublicationsServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        String[] pathInfo = request.getPathInfo().split("/");
        System.out.println(Arrays.toString(pathInfo));
        ...
    }
}


例如,如果我有这样的网址:
http://localhost:8080/bulletinboard/publication/topic/SALE

我想省略空字符串。所以pathInfo导致[SALE]而不是[,SALE]

如何实现?

最佳答案

您可以省略第一个字符,因为它总是斜杠:

request.getPathInfo().substring(1).split("/")

09-05 08:48