I'm new in Servlet
I get parameters like this (localhost:1313/JEE/servlet?id=1) in post or get method
but I have a question
can I receive this parameter in this way "localhost:1313/JEE/servlet/1"
exactly get localhost:1313/JEE/servlet/1 (instead of) localhost:1313/JEE/servlet?id=1
omar al kababji wrote:no you can't ...
Of course you can; just not via getParameter. You'll need to fetch and parse the path info yourself (or look to something like JAX-RS). The getPathInfo method will return the trailing path information if you map the servlet with a trailing wildcard.
and yes you can do it by parsing the string, but you will be doing at by yourself. my question would be why would you need to use a different encoding to pass parameters to your servlets? and why would you use such a way that will limit you to using only GET methods?
omar al kababji wrote:"friendly urls" honestly i don't like the idea, friendly for whom? for the programmer? i think that the normal url's are much more friendly for a programmer than having him to use a different url. in addition i don't a good explanation for having a friendly url for the user of a web application, in then end its better to not making him understand whats data gets in and out from the parameters, making the website more vulnerable.
So you're either not a real web programmer or you've somehow never heard of SEO.
I also don't see how it increases the vulnerability, so you're just babbling somewhat randomly. Please come up with reasonable arguments.
Again i don't find a good reason for it.
have a nice day.
ArAsh Dex wrote:now it will not return error in some link like localhost:1313/JEE/testShow/1
Correct? It's perfectly valid according to your mapping.
is it good solution? or not?
That depends. Why are you wanting to do it this way? Using the path info rather than the usual request parameters is more work and is not directly supported by the Servlet API.
So if you have a good reason for doing it this way, then maybe it's worth it. If you are doing it "just because", not so much.
get localhost:1313/JEE/servlet/1 (instead of) localhost:1313/JEE/servlet?id=1
and i thought maybe I can solve it with servlet mapping in web.xml
and don't have problem right now
I'll try to find other way such as 'pretty urls', and i hope can find the best way
many many many thanks my amigos
Mr. Bear Bibeault(as always) , Mr. Bauke Scholtz & Mr. Omar al kababji
where testShow identifies the servlet and "1" has to be interpreted by the servlet is perfectly good REST style programming.
Not perhaps where a complete beginner should start but a valid approach and supported by Sun's Jersey project and numerous others.