response.sendRedirect在Struts2磁贴中不起作用 [英] response.sendRedirect not working in Struts2 tiles

查看:195
本文介绍了response.sendRedirect在Struts2磁贴中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个带有tile的struts2项目,我想在其中使用关键字从一个jsp页面重定向到另一个页面,

I am developing a struts2 project with tiles in which I want to use the keyword for redirecting from one jsp page to other page as,

   <%
    response.sendRedirect("search");
    %>

在普通的jsp页面中,代码工作正常.

In normal jsp pages the code is working as.

response.sendRedirect("search.jsp");

但是当我使用瓷砖时,它不起作用.

but when I use with tiles, its not working.

当我直接运行页面时,其重定向,但是当我将此页面称为其他页面时,其不重定向.我尝试使用空白html页面的代码而不进行任何其他编码,但仍然无法正常工作.

when I am running the page directly its redirecting, but when I call this some other page its not redirecting. I tried the code with blank html page without any other codings, still its not working.

搜索"是struts.xml页中操作的名称.我需要在response.sendRedirect中添加任何额外的属性吗?

"search" is the name of the action in struts.xml page. Is there any extra attribute I need to add in response.sendRedirect ?

当前我正在使用

<META HTTP-EQUIV="Refresh" CONTENT="0;URL=search">

为了做好我的工作.是否会在任何方面造成任何问题?

for doing my job. Whether it will create any problem in any aspect?

我检查了重定向到多个位置的条件,使其正常工作.

I checked it with conditions for redirecting to multiple places, its working.

 <%    
    int k=0;
    if(k==1){
    %>

    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=search">
    <%
    }
    else 
    {
    %>

    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=guestprofile">
    <% 
    } 
    %>

据我从答案中了解到,尝试过这样

As I understood from answer, tried like this

response.sendRedirect("viewuniqueRedirect"); 

在页面和

<action name="viewuniqueRedirect" > <result type="chain">viewunique</result> </action> 

在struts.xml中,但不起作用

in struts.xml, but not working

推荐答案

您应该怀疑您的元标记方法非常丑陋.

You are right to suspect your meta tag method as being very ugly.

使用struts2,您将返回图块结果类型.这是在您的struts.xml中定义的,或者对该操作进行了注释以产生此结果.

With struts2 you are returning a tiles result type. This is either defined in your struts.xml or the action is annotated to produce this result.

您要重定向的动作不应返回图块结果类型,而应返回redirect/redirectAction类型.有关这些结果之一,请参见此处:在struts.xml中进行操作重定向

Your action which you want to redirect should NOT be returning a tiles result type but a redirect/redirectAction type. For one of these results see here: Action redirect in struts.xml

您的操作应执行所有必需的处理(如果有),并且图块应构成视图.如果您确实打算重定向,那么尝试撰写任何视图都是很浪费的.

Your action should do all the required processing (if any) and tiles should compose the view. If you really intend to redirect, it is a waste to try to compose any view what so ever.

您指出的问题(此处)在这种情况下可能仍然适用.也就是说,如果您已经编写了内容,则无法重定向,并且可以尝试在写入任何其他内容之前重定向并返回,但是平铺通常是由多个视图组成的……并且将继续写入HTTP响应,因此可能使重定向无效.如果您只有一个jsp组成视图,那么我就不知道了.但是我再一次根本不考虑调用磁贴.

The question which you pointed to (here) probably still applies in this context. That is you can not redirect if you have written content and you may try to redirect and return before writing any further content but tiles is often composing from several views... and will continue to write to the HTTP response and thus likely null the redirect. If you only have a single jsp composing the view, then I don't know. But once again I would not think to invoke tiles at all.

这篇关于response.sendRedirect在Struts2磁贴中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆