0

Is there anyone her who knows how to use slashes as querystring. What I want to do is using the url:

http://sample.com/urltest/?id=23423ea342

to appear as

http://sample.com/urltest/23423ea342

and handel it onto the Servlets or Struts Action Class

Atul Darne
  • 746
  • 7
  • 14
  • that's called URL rewriting, but your question is way too broad for SO. So the best thing to do would be googling those terms and learn a bit more from there. – Laurent S. Apr 08 '14 at 13:53
  • Instead you should have correct Servlet of Action class which have method mapped to `http://sample.com/urltest/` and accepts `id` as request parameter – Ajinkya Apr 08 '14 at 13:54
  • You could use a regex and replace {'?id='} through '' (an empty string). http://www.vogella.com/tutorials/JavaRegularExpressions/article.html – user2718671 Apr 08 '14 at 14:08
  • I dont want a ? Into the query string , it should have only slashes. Is there any tutorial where i can get some idea regarding this ? – Atul Darne Apr 08 '14 at 14:16

2 Answers2

0

add this to .htaccess file

RewriteEngine On
RewriteRule ^(.*)$ /sample.com/urltest/?id=$1 [L]
BackSlash
  • 21,927
  • 22
  • 96
  • 136
Omar Sedki
  • 608
  • 6
  • 14
  • 2
    You should also explain what this does, otherwise the OP learns nothing from this answer. – BackSlash Apr 08 '14 at 13:59
  • In addition to the comment above, you should also mention that the `RewriteRule` above will rewrite any requests since it is `.*` (`^` and `$` are not necessary in this case). – Rolice Apr 08 '14 at 14:05
  • I have seen many payment gateways or reportieng tools that use this way of url e.g http://www.gateway.com/userauth/txn678257/reportxml/ – Atul Darne Apr 08 '14 at 14:21
0

Well, if i understood what is OP asking for, the simplest way for me to do this is use JAX-RS, aka Java API for RESTful Web Services

Here is the JAX-RS oracle tutorial: http://docs.oracle.com/javaee/6/tutorial/doc/giepu.html

And here is an example service class for your example URL:

@Path("/")
public class testClass {

    @GET
    @Path("/{id}/")
    @Produces(MediaType.APPLICATION_JSON)
    public Response testMethod(@PathParam(value = "id") String id) {

        return Response.ok().entity("HELLO! You sent me this id: " + id).build();

    }

} 

Assuming that /urltest is the path configured for your base url, this service will be invoked with the following URL: http://sample.com/urltest/23423ea342

and the "23423ea342" will be your {id} parameter for your service

Cirou
  • 1,420
  • 12
  • 18