Servlet Mapping Help - Possible to Avoid Referencing Context Name?

Posted by AJ on Stack Overflow See other posts from Stack Overflow or by AJ
Published on 2010-04-23T17:58:06Z Indexed on 2010/04/23 18:13 UTC
Read the original article Hit count: 272

Filed under:
|
|
|

Hi all,

I am working on a Spring application and 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!

© Stack Overflow or respective owner

Related posts about j2ee

Related posts about spring