renan gado
renan gado

Reputation: 59

How to display URL link different than page JPS page?

I am not sure it this is possible at all. I see that in Facebook when you crate a business page you will get a link with page number, for example:

https://www.facebook.com/degendaUK/

I would like to know if it is possible to create a link like that without having an HTML or JSP page called "DegendaUK" for example.

In my code I have page

http://localhost:8080/offers/empresa?get_Business_ID=29-11-2017-03:39:22R7M5NZ8ZAL

The standard page is called "Empresa" and then I pass the ID so I can query the database.

Is there anyway that instead of my URL I would get

http://localhost:8080/offers/BUSINESS-NAME

without creating a JSP page for each business?

I am using Spring MVC.

Upvotes: 0

Views: 93

Answers (1)

TomB
TomB

Reputation: 1110

You may use Spring @Controller, @RequestMapping and @PathVariable annotations to do this.

@Controller
public class Controller
{
    @RequestMapping(value = "/offers/{id}")
    public String offer(@PathVariable String id, final Model model)
    {
        //pass the value from the url to your jsp-view, access it via ${id} from 
        //there
        model.add("id",id);  
        //render the page "empressa.jsp"
        return "empressa";
    }
}

Hint: You may need some and in your XML config to make those annotations work. If your using spring-boot, this should be preconfigured already an work out of the box.

Don't forget to secure those things if they're not public things using spring-security :)

Upvotes: 1

Related Questions