0

I'm sorry, I come from a PHP web world.

I'm used to using a router in frameworks like Laravel to send to controllers and get parameters. I know how to get get and post parameters using servlets by routing things with the web.xml servlet-mapping and using * wildcards, but am unfamiliar with how to get those url wildcards with the HttpServletRequest variable passed through doGet or doPost.

Is there anything where I can grab the wildcards of those urls, such as, if the url was a username or a particular page I didn't want to hard code into the web.xml? I'm sure there is.

Id like to know things like what I can get in PHP's $_SERVER variables for reading data about the incoming request. Stuff like cookies are also needed. Can someone give me a quick pointer with Java Servlets?

EDIT:

Or maybe I should just stick the variables to where variables belong and not make "pages" out of fake variables. I'm also open to that idea as well.

My main problem is that I don't know how to get url wildcards in doGet or doPost after it's routed from web.xml, so I'd either like to know how or be told that's a stupid thing to do and not do it at all.

Alexander Kleinhans
  • 5,950
  • 10
  • 55
  • 111

1 Answers1

0

Check out Spring MVC. With Spring Controllers you get to do URL paths like

@RequestMapping("/fixed/{id}/{user}")
public String getSomeData(@PathVariable("id") String id, @PathVariable("user") String user) {
...
}

or even

@RequestMapping("/{id}/**")
public void doSomething(@PathVariable("id") int id, HttpServletRequest request) {
String remainingUrl = (String) request.getAttribute(
    HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
...
}
BetaRide
  • 16,207
  • 29
  • 99
  • 177
Jan
  • 13,738
  • 3
  • 30
  • 55