0

i have a situation where an email is sent to a user containing a url in the format http://xxxxxxxxxx/user=ABCXYZ

where ABCXYZ is a randomly generated 6 digit alphanumeric code. My question is when the URL is clicked it should redirect to my application's servlet and that should be done from web.xml. Any lead would be appreciated. Also is there any other way for the same?

Akash Sharma
  • 1
  • 1
  • 1
  • 5
  • Well, every servlet has a URL mapping, either in the web.xml (using ) or using the `@WebServlet` annotation. So if you can define a servlet and its URL mapping, whether the user clicks a link from an email or not is irrelevant. What's the concrete problem? – JB Nizet Dec 18 '16 at 07:56
  • how to redirect to servlet when the url is clicked. in url mapping tag if i give url patter as /user=* will that do? – Akash Sharma Dec 18 '16 at 08:00
  • There is bo "redirect". If you have a link to http://foo.com/bar in an email, clicking the link will send a GET request to http://foo.com/bar. So, just make sure that you put a link with URL of the servlet in the mail. Or vice-versa, that the link in the email has the URL of your servlet. `/user=ABCXYZ` is not a valid path, so nothing will do. Choose a valid URL, like `/user?id=abcxyz`, or `/user/abcxyz`. – JB Nizet Dec 18 '16 at 08:01
  • but i got to do it that way as thats the requirement, can't go with other formats. Although earlier i was redirecting to jsp page where page was mentioned in the url and i dint had to do anything the web.xml. – Akash Sharma Dec 18 '16 at 08:07
  • Tell the guy that rote the requirement that he'd better change it, because the URL he chose is not a valid URL, and that the standard specifications for URLs used by the whole world won't change just because he would like his URL to look that way. You wouldn't make a car with square wheels even if "that's a requirement", would you? – JB Nizet Dec 18 '16 at 08:09
  • say if i can slightly modify the url then whats the best possible way to do this? – Akash Sharma Dec 20 '16 at 13:54
  • Use `/user?id=abcxyz`, map your servlet to `/user` and use request.getParameter("id") to get the user ID. – JB Nizet Dec 20 '16 at 16:57
  • Thanks, that helped me, got the url pattern changed. – Akash Sharma Dec 21 '16 at 06:39

0 Answers0