0

Regarding this post: how to redirect url to jsp in web.xml

it is obvious that one can make an url, for example, http://mypage.com/details/?id=20 where details is mapped to details.jsp

<servlet>
    <servlet-name>details</servlet-name>
    <jsp-file>/details.jsp</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>details</servlet-name>
    <url-pattern>/details/*</url-pattern>
</servlet-mapping>

So, my question is as follows:

  1. how would I get the "/details/" parameter from the url within a .jsp (or servlet)?
  2. is it possible to format the url in this manner http://mypage.com/details/20/ and if so, how?

Thanks!

Community
  • 1
  • 1
None None
  • 537
  • 2
  • 8
  • 15

1 Answers1

0

I think you can get that and use it as variable using Spring MVC Framework or get the requestUri.

example: mypage/detail/20

String requestUri = request.getRequestUri();
int x = Integere.parseInt(requestUri.subString(requestUri.lastIndex('/',requestUri.length())));

out.println("value of x is " + x);

Try to study Spring MVC Framework