This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes How we dynamically change url in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How we dynamically change url in Java" Watch "How we dynamically change url in Java" New topic
Author

How we dynamically change url in Java

Ramesh Sengani
Ranch Hand

Joined: Nov 23, 2011
Posts: 36
Hi,

I working in site where i want to make url SEO friendly . l

Eg .

http://ramesh.org/FAQ_How_do_I_increase_the_permgen_size_available_to_Eclipse


http://www.rameshsengani.com/t/560067/java/java/Random-Numbers-Do-Not-Repeat


this url redirect to some specific page where some topic related to permgen discussed.

How this type of things achieve in servlet. Based on title or some specific line of page we fetch data from database and will show in jsp. I want data come from database not static html page.


Please guide.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19726
    
  20

Use a URL mapping to map everything inside the "folder" to your servlet. I'm not sure but I think here the URL mapping is for /forums/*.
Then retrieve the full URL from the HttpServletRequest, and use its contents to determine what to display.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ramesh Sengani
Ranch Hand

Joined: Nov 23, 2011
Posts: 36
Thanks for reply Rob.

But for that my page and topic i have to put predefine. That is not possible in case where some new topic is add. Every time i cant add mapping for each topic .It should be dynamic.

You take example of coderanch, where for every topic, url is changing and its showing topic name in url. that i want in my site.





Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42374
    
  64
A mapping does not need to be static, it can change at runtime if it's under your code's control (like in the servlet that Rob talks of). The only fixed part of the URL is the ID; as a matter of fact, everything behind that is completely ignored - you're free to put anything you want there. http://www.coderanch.com/t/560763/kilroy-was-here works just as well as http://www.coderanch.com/t/560763/ or http://www.coderanch.com/t/560763/java/java/we-dynamically-change-url-Java


Ping & DNS - my free Android networking tools app
Ramesh Sengani
Ranch Hand

Joined: Nov 23, 2011
Posts: 36

Thanks for reply Ulf Dittmer. I understand your post.

But in url how can i add that extra things like 'title'. I want to understand at code level.
suppose

My request coming with

http://www.coderanch.com/forums/forums/posts/reply/0/560763

and now i want cancat title of their respective id .

http://www.coderanch.com/forums/forums/posts/reply/0/560763/what_is_name

How should i do this .? I tried my best but not get success.

Please reply with needful with some example....Its urgent .


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19726
    
  20

Please EaseUp. There is no such thing as urgent around here.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42374
    
  64
How can something that came up yesterday already be urgent today? That's a ridiculous schedule for a new feature.

I'm not sure what the problem is - as I said, the part behind the ID is completely ignored, so you can put anything you want there, including the post's title. What problem are you having implementing that, specifically?
Ramesh Sengani
Ranch Hand

Joined: Nov 23, 2011
Posts: 36

Extremely apologize for my mistake.

Ok i will give brief description what is my requirement ..

I am working in a one website which i want to make SEO friendly....

as you said i am using id for retrieve topic from database but parallely i also want to cancat title of the topic in that url .

www.gooe.com/forum/1234

this type of request is coming from browser but while showing i want to show

www.gooe.com/forum/1234/title_of_topic


For that i made front controller, which accept all request and based on id fetch title of page,and redirecting to respective action class.
but i am not getting ,how i will cancat title with result url in browser.




Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42374
    
  64
Still not following - are you asking how to transform the string "/forum/1234 " into "/forum/1234/title_of_topic"? If so, you have the ID of the post , so you can look up the subject, and then append it to the string before you do the redirect. And, of course, wherever the URL is used in your web pages, you'd append the subject to begin with.
Ramesh Sengani
Ranch Hand

Joined: Nov 23, 2011
Posts: 36
thanks I got your point. .thank you very mach.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How we dynamically change url in Java