0

In my struts2 based application i need to include working template (a jsp file).I have designed the layout and has everything in place.only part of application which will change throughout the application is working area.

On my index.jsp file i need to include menu which are database driven and for which i need to hit the action one way which is coming to my mind is like using

<META HTTP-EQUIV="Refresh" CONTENT="0;URL=welcome.action">

in the head section of my index.jsp,but i don't want to have redirect at first place in my application.

is there any other way to achieve this?

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204

2 Answers2

1

That's a normal approach; nothing wrong with it.

Another is to define an action as a welcome page, but you'll need to define dispatcher elements on the filter as per this SO answer.

Community
  • 1
  • 1
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • is it not same as the redirection,since in all cases URL will be www.mysite.com/welcome but i want it to be simple like www.mysite.com – Umesh Awasthi Dec 13 '11 at 15:43
  • @user577691 Then use the second mechanism. You could also try using a JSTL include. – Dave Newton Dec 13 '11 at 16:01
  • may be i am understanding it in wrong way but if i will go for second option the dispatcher one still in my welcome file list i have to define the action URL, so i believe action URL will be same like www.mysite.com/welcome where `welcome` will be the name of action. – Umesh Awasthi Dec 13 '11 at 16:06
0

create an empty file name welcome in your web-content folder.Add follwinf 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="welcome.action">
        <result>/index.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.In this case your URL will remain same say www.mysite.com

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204