开发者

Spring URLs: There's a difference between "/test" and "/test/" in the controller mapping

Simple example spring controller (if you're not familiar with spring, just look at the output html):

@Controller
@Reque开发者_如何学JAVAstMapping("test")
public class TestController {
    @RequestMapping("")
    @ResponseBody
    public String pathTest(){
        return "<html><head></head><body><a href='subpath'>subpath</a></body></html>";
    }
}

If I go to http://mydomain/test, the link from the above html goes to: http://mydomain/subpath

If I go to http://mydomain/test/, the link from the above html goes to: http://mydomain/test/subpath

I guess this is simple, but I don't know how to ensure that the trailing '/' doesn't affect the application function. My primary concern is when users manually change the URL, they may or may not leave the trailing '/'.

What can I do to ensure my application works the same whether or not the final '/' exists?


Do not return <a href='subpath'>subpath</a> return

<a href='/test/subpath'>subpath</a> instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜