31

我在我的应用程序中使用 Spring 3 和 Tiles 2,并且在重定向时遇到了一些麻烦。最好,我希望能够从 Controller1 方法调用或重定向到 Controller2 方法,但到目前为止还没有成功。

我试图在 pageviews.properties 文件中创建一个新条目。这样我就可以从 Controller1 返回这个名称,它会从 xml 文件中查找我的切片定义名称。

createRejectionEmail.(parent)=tilesView
createRejectionEmail.url=createRejectionEmail.page

redirectRejectionEmail.(class)=org.springframework.web.servlet.view.RedirectView
rediectRejectionEmail.contextRelative=true
redirectRejectionEmail.url=createRejectionEmail.page

但是,当我尝试如下所示返回时,我的 URL 包含 createRejectionEmail 作为 URL 的一部分 - 而不是使用它在切片 defs 中进行查找。mav.setViewName("redirectRejectionEmail"); 返回mav;

<definition name="createRejectionEmail.page" extends="brandedLayout">
  <put-attribute name="targetFunction" value="status" />
  <put-attribute name="content" value="/WEB  INF/jsp/pages/status/createRejectionEmail.jsp" />
</definition>

我当前的配置如下。

<bean id="resourceViewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver"
p:order="0" p:basename="config.spring.viewresolution.pageviews"/>



<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
   <list>
  <value>/WEB-INF/jsp/**/views.xml</value>
    </list>
</property>
</bean>

任何帮助和指导将不胜感激!

4

2 回答 2

61

From your controller you can change the return type to be a ModelAndView and return code below. This will re-direct the request and call the controller for the new URL.

return new ModelAndView("redirect:/myURL");

Alternatively you could take in the HttpServletResponse in your controller method and return a redirect.

public void myController(HttpServletResponse response){
response.sendRedirect("/myURL");
}
于 2013-06-21T10:03:46.160 回答
9
@RequestMapping(value = "/timeout", method = RequestMethod.GET)
    public ModelAndView loginForm(HttpServletRequest request,HttpServletResponse response) {


                return new ModelAndView("redirect:/app/timeout");

    }

When this method handler call then it redirect to the /app/timeout controller.

于 2014-11-14T06:21:34.053 回答