java - How to redirect to spring controller method in app deployed on local server? -
on local tomcat server develop few projects. 1 of them write in spring mvc. want redirect request method of controller. know it's possible use: return "redirect:/path/to/resource"; if have deployed app on tomcat have use prefix like: return "redirect:/appname/path/to/resource";. how make work on server prefix , without?
it sounds you're having trouble because you've got app running root context in environments , not in others. can use methods available on httpservletrequest , httpservletresponse objects redirect more environment independent. example spring controller method this:
@requestmapping("/test") public void test(httpservletrequest request, httpservletresponse response) throws ioexception { string url = request.getscheme() + "://" + request.getservername() + ":" + request.getserverport() + request.getcontextpath() + "/path/to/resource"; response.sendredirect(url); } the getcontextpath part in particular solves problem you're talking about, return / if app running root context return /appname if app running appname in example.
Comments
Post a Comment