Reputation: 5963
Basically when the user goes to example.com
I want to serve it the same content I would have, if it went to example.com/news
. Below is the code snippet.
Current COnfig
<action name="" class="action.public.news">
<result>/jsp/labs/listLabs.jsp</result>
</action>
<action name="news" class="action.public.news">
<result>/jsp/labs/listLabs.jsp</result>
</action>
Desried COnfig
<action name="" class="action.public.news">
Use Action Named "news" instead
</action>
<action name="news" class="action.public.news">
<result>/jsp/labs/listLabs.jsp</result>
</action>
Upvotes: 0
Views: 496
Reputation: 23587
If i understand it right you want that when user hit the base domain example.com
it should fetch the content of the action news
one way to do this is.
create an empty file name welcome in your web-content folder.Add following entry to your web.xml
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
replace your welcome list file in web.xml as
<welcome-file-list>
<welcome-file>welcome</welcome-file>
</welcome-file-list>
and finally in your strus.xml do something like
<action name="welcome" class="action.public.news">
<result>/jsp/labs/listLabs.jsp</result>
</action>
what we are trying to do is that when we hit example.com
instead of showing the welcome jsp file we are hitting the action and using its result
Upvotes: 1
Reputation: 7141
Most people create a index.jsp page in the webapp folder containing this:
<% response.sendRedirect("index.action"); %>
This will redirect the visitor to the index.action when they arrive at your domain. Then, in struts.xml:
<action name="index" class="action.public.news">
<result>/jsp/labs/listLabs.jsp</result>
</action>
Cheers, Christian
Upvotes: 0