rdp
rdp

Reputation: 2088

Resolve a URL request containing .jsp in Spring

I have created a Spring Web MVC project. I want to handle request with with .jsp in the url such that all request with .jsp in the URL are handled by the same controller.

Following is the url pattern I am using in web.xml

<servlet-mapping>
        <servlet-name>project</servlet-name>
        <url-pattern>/</url-pattern>
</servlet-mapping>

The annotation in the Controller looks like this

@RequestMapping("/welcome")

With this I am able to resolve URL of the form http://localhost:8080/project/welcome

But not this one : http://localhost:8080/project/welcome.jsp

Upvotes: 0

Views: 687

Answers (3)

Alok kumar
Alok kumar

Reputation: 9

It's very easy you can do using below technique

Add below code in your controller

@RequestMapping("/{jspName}.jsp")
     public String allRequestProcess(@PathVariable("jspName") String jspName) {
        System.out.println("JSP Page Name : " + jspName);
     }

but it will hard to handle every such request in one controller. try to avoid such situation. Better to use some else than .jsp

Upvotes: 0

Serge Ballesta
Serge Ballesta

Reputation: 149085

That's a very uncommon requirement for a spring MVC controller, but spring is a very versatile tool.

You can try this (untested ...) :

@RequestMapping("/{name}.jsp")
public ModelAndView jspHandler(@PathVariable("name") String name) {
...

The controller will get all *.jsp requests and you will find in name variable the real name by which it has been called

Upvotes: 2

Jason
Jason

Reputation: 1241

You can using this :

@RequestMapping(value={"/welcome","/welcome.jsp"})

Upvotes: 1

Related Questions