开发者

Simplest way to use a variable in the URL in servlets

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜