Response.sendRedirect not working in Struts2 slabs

I am developing a struts2 project with elements in which I want to use the keyword to redirect from one jsp page to another page, since

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

On regular jsp pages, the code works like.

 response.sendRedirect("search.jsp"); 

but when i use tiles it doesn't work.

when I launch the page directly, redirecting it, but when I call this other page, it does not redirect. I tried the code with an empty html page without any other encodings, but it didn't work.

"search" is the name of the action on the struts.xml page. Is there an additional attribute that I need to add to response.sendRedirect?

I am currently using

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

to do my job. Will this create any problems in any aspect?

I checked it with the conditions for redirecting to several places, its work.

  <% 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 the answer, I tried it like this

 response.sendRedirect("viewuniqueRedirect"); 

on page and

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

in struts.xml but not working

0
jsp struts struts2 response.redirect tiles
source share
1 answer

You are right if you suspect that your meta tag method is very ugly.

With struts2, you return the result type of the tile. This is either defined in your struts.xml, or the action is annotated to get this result.

Your action you want to redirect should NOT return the result type of the tile, but the redirection / redirectAction type. For one of these results, see here: Forwarding actions in struts.xml

Your action should do all the necessary processing (if any), and the tiles should make up the view. If you really intend to redirect, take the time to try to get some idea of ​​what happened.

The question you pointed out ( here ) is probably still applicable in this context. That is, you cannot redirect if you have written content, and you can try redirecting and returning before writing any additional content, but the tiles are often composed of several views ... and will continue to write HTTP responses and probably If you only have one jsp making up the view, then I don't know. But again, I would not come up with tiles at all.

+2
source share

All Articles