1

So I am trying to build a simple site that works like this.

Normally: www.XYZ.com/hello?id=912 (in this case the parameters inputed are id which is 912) In this case, the class "hello" extends HTTPServlet

Preferred Way: www.XYZ.com/hello/912(In this appended after a forward slash is in the url itself)

What would I do here? instead of extending another HTTPServlett

Thank you for your time

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
Mathew Kurian
  • 5,949
  • 5
  • 46
  • 73

3 Answers3

2

Map your servlet to /hello and parse the result of HttpServletRequest.getPathInfo()

Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
2

You should look into Spring MVC. It offers has @RequestMapping annotations for controllers which make this extremely painless to accomplish. AND it allows you to cleanly separate the different layers of your application (the data, the control and the presentation layers) without too much fuss.

Here's a good introduction: http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example/ and more specifically http://www.mkyong.com/spring-mvc/spring-3-rest-hello-world-example/

sje397
  • 41,293
  • 8
  • 87
  • 103
JustDanyul
  • 13,813
  • 7
  • 53
  • 71
1

I hope I'm not shooting flies with cannon here, but, have you considered using a framework like restlet so you can associate URLs to methods even more flexibly?

Miquel
  • 15,405
  • 8
  • 54
  • 87