views:

63

answers:

2

Hi all,

I am working on a Spring application using Tomcat 6 and Spring 2.5. I'm trying to get my URL mapping correct. What I would like to have work is the following:

http://localhost:8080/idptest -> doesn't work

But instead, I have to reference the context name in my URL in order to resolve the mapping:

http://localhost:8080/<context_name>/idptest -> works

How can I avoid the requirement of referencing the context name in my URL without using a rewrite/proxy engine e.g. Apache?

Here is the servlet definition and mapping from my web.xml:

<servlet>
    <servlet-name>idptest</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/conf/idptest.xml</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup> 
</servlet>

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

Here's the outline of my controller (showing annotations for request mappings):

@Controller
@RequestMapping("/idptest")
public class MyController  {

    @RequestMapping(method=RequestMethod.GET)
    public String setupForm(Model model){
            MyObject someObject = new MyObject();
        model.addAttribute("someObject", someObject);
        return "myform";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@ModelAttribute("someObject") MyObject someObject) throws Exception {
        // POST logic...
    }
}

Thanks!

+4  A: 

That's going to depend on your servlet container, for Tomcat - you pretty much have to deploy your webapp as the ROOT webapp, that is, under $CATALINA_HOME/webapps/ROOT/

More info here

nos
@nos thanks, updated my question w/ the container and version.
AJ
+1  A: 

Just rename your war file to ROOT.war, then the application runs in root context (i.e. with empty context name)

Dominik