Related to: How can I set the welcome page to a struts action?
I'm trying to redirect my welcome page index.jsp to an action (Struts2). None of options in related post worked for me:
type Status report
message /malelo/indexRedir
description The requested resource (/malelo/indexRedir) is not available.
I'm follow this FLOW structure:
http://localhost:8580/malelo/ SEND TO WELCOME PAGE
---> (root)index.jsp SEND USER TO (by redirect, I need forward)
---> (indexRedir) IndexAction.java SEND USER TO
---> (WEB-INF/content) index-login.jsp
This worked, but not too elegant (index.jsp):
<%
response.sendRedirect("indexRedir");
%>
I'm trying to do this (index.jsp):
<jsp:forward page="indexRedir" />
I'm using only Annotation, no XML files configuration, please.
@Action (value = "indexRedir", results =
{ @Result (location = "index-login.jsp", name = "ok") } )
EDIT
Just to clarify, this is the http header sent to browser by a response.sendRedirect :
HTTP/1.1 302 Found
Date: Tue, 27 May 2014 16:15:12 GMT
Location: http://cmabreu.com.br/basico/
Content-Length: 0
Connection: close
Content-Type: text/plain
This location (http://cmabreu.com.br/basico/) points to a index.jsp with:
<%
response.sendRedirect("indexRedir");
%>
And show the content of a JSP page pointed by indexRedir action. Google Webmasters Tools and some bots don't follow pages like that.
See more here: http://en.wikipedia.org/wiki/HTTP_302
In order to forward to an action you must configure filters to run on forwards; normally they don't, although this is container-dependent. For example, under Tomcat:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher> <!-- If you want includes as well -->
</filter-mapping>
Personally, I don't find the redirect particularly inelegant, and it's pretty standard.
The other benefit is that you shuttle people into the action-based app; with the forward your URL doesn't change. In general you'd want to disallow JSP-based URLs.