开发者

Simplest way to use a variable in the URL in servlets

开发者 https://www.devze.com 2023-01-01 06:59 出处:网络
What is the simplest way to use a varia开发者_开发技巧ble in the URL in servlets. Eg. http://somesite.com/MyServlet/[ID]That\'s called path info. You can use HttpServletRequest#getPathInfo() to grab

What is the simplest way to use a varia开发者_开发技巧ble in the URL in servlets.

Eg. http://somesite.com/MyServlet/[ID]


That's called path info. You can use HttpServletRequest#getPathInfo() to grab it.

String pathInfo = request.getPathInfo(); // "/[ID]"

This however includes the leading slash. You may want to substring it away as follows:

String pathInfo = request.getPathInfo().substring(1); // "[ID]"

This assumes that your servlet is mapped on an url-pattern of /MyServlet/*.

0

精彩评论

暂无评论...
验证码 换一张
取 消