You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Antonio Sánchez <in...@gmail.com> on 2013/05/31 20:17:53 UTC

Actions as welcome files

Hello.

My name is Antonio, I'm beginning with Struts2 and this is my first post.

Where should store struts.xml if I need to use an action as a welcome file?

In example "Hello World" (maven):

http://struts.apache.org/development/2.x/docs/hello-world-using-struts-2.html

I have to move struts.xml (originally inside resources folder) inside 
maven 'main' folder to make it work and avoid

     HTTP 404 - There is no Action mapped for namespace [/] and action 
name [] associated with context path [/Hello_World_Struts2_Mvn].

but then struts.xml is unreachable in Netbeans project window.

In this crud example:

http://struts.apache.org/development/2.x/docs/hello-world-using-struts-2.html

I can't find the right way. I have updated libs to the latest ones. 
struts.xml is in WEB-INF/classes in war file deployed by Netbeans 
(Tomcat 7).

Bellow struts and web xmls

<struts>
     <!-- Include webwork default (from the Struts JAR). -->
     <include file="struts-default.xml"/>

     <!-- Configuration for the default package. -->
     <package name="default" extends="struts-default">

         <!-- Default interceptor stack. -->
         <default-interceptor-ref name="paramsPrepareParamsStack"/>
         <action name="index" 
class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="list">
             <result name="success">/WEB-INF/jsp/employees.jsp</result>
             <!-- we don't need the full stack here -->
             <interceptor-ref name="basicStack"/>
         </action>
         <action name="crud" 
class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="input">
             <result name="success" type="redirectAction">index</result>
             <result name="input">/WEB-INF/jsp/employeeForm.jsp</result>
             <result name="error">/WEB-INF/jsp/error.jsp</result>
         </action>
     </package>
</struts>


<web-app>
     <display-name>Struts 2 Demo</display-name>

     <welcome-file-list>
         <welcome-file>index.action</welcome-file>
     </welcome-file-list>

     <filter>
         <filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
     </filter>

     <filter-mapping>
         <filter-name>struts2</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
</web-app>

Thanks.




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Actions as welcome files

Posted by Chris Pratt <th...@gmail.com>.
In my experience most containers rely on the existence of the file
specified in the <welcome-files>, but don't directly use it.  Because of
this, if you define your welcome file as:

<welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

Then create a dummy (or even 0 byte length) index.jsp file, your container
will actually go through the normal process of filling the request, which
will allow Struts2 to do it's normal processing and return the requested
result.

I know it works well with Resin and other containers, but YMMV.
  (*Chris*)



On Fri, May 31, 2013 at 12:00 PM, Lukasz Lenart <lu...@apache.org>wrote:

> 2013/5/31 Antonio Sánchez <in...@gmail.com>:
> > I have to move struts.xml (originally inside resources folder) inside
> maven
> > 'main' folder to make it work and avoid
> >
> >     HTTP 404 - There is no Action mapped for namespace [/] and action
> name
> > [] associated with context path [/Hello_World_Struts2_Mvn].
> >
> > but then struts.xml is unreachable in Netbeans project window.
>
> You shouldn't do that ... struts.xml must lay in resource folder (it
> will be copied to WEB-INF/classes during package phase)
>
>
> > I can't find the right way. I have updated libs to the latest ones.
> > struts.xml is in WEB-INF/classes in war file deployed by Netbeans (Tomcat
> > 7).
> >
> > Bellow struts and web xmls
> >
> > <struts>
> >     <!-- Include webwork default (from the Struts JAR). -->
> >     <include file="struts-default.xml"/>
>
> Struts2 include this file by default, you don't have to do this (it
> can even be source of unpredictable problems)
>
> >     <!-- Configuration for the default package. -->
> >     <package name="default" extends="struts-default">
> >
> >         <!-- Default interceptor stack. -->
> >         <default-interceptor-ref name="paramsPrepareParamsStack"/>
> >         <action name="index"
> > class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="list">
> >             <result name="success">/WEB-INF/jsp/employees.jsp</result>
> >             <!-- we don't need the full stack here -->
> >             <interceptor-ref name="basicStack"/>
> >         </action>
> >         <action name="crud"
> > class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="input">
> >             <result name="success" type="redirectAction">index</result>
> >             <result name="input">/WEB-INF/jsp/employeeForm.jsp</result>
> >             <result name="error">/WEB-INF/jsp/error.jsp</result>
> >         </action>
> >     </package>
> > </struts>
>
> You have two options here:
> - define action with blank name (I don't like it as this is some kind
> trick and not expected behaviour), ie.
>     <action name=""
> class="com.aurifa.struts2.tutorial.action.EmployeeAction"
> method="input">
> - define default-action-ref per package
>     <default-action-ref name="index/>
>
> <welcome-files/> will not work as most of the containers doesn't allow
> forwarding to non-static resources, you can try to define struts2
> filter as below to achieve that:
>
> <filter-mapping>
>         <filter-name>struts2</filter-name>
>         <url-pattern>/*</url-pattern>
>         <dispatcher>REQUEST</dispatcher>
>         <dispatcher>FORWARD</dispatcher>
>         <dispatcher>INCLUDE</dispatcher>
> </filter-mapping>
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Actions as welcome files

Posted by Antonio Sánchez <in...@gmail.com>.
Yes, this makes it work. 

I'm just using the examples linked in the tutorials. IMHO, tutorials and examployees, if 
possible, should be updated with working code and best practices. In my case I have 
spent time with this issue.

I have posted this issue to JIRA.

Thank you all!


El Viernes, 31 de mayo de 2013 21:00:24 Lukasz Lenart escribió:
> 2013/5/31 Antonio Sánchez <in...@gmail.com>:
> > I have to move struts.xml (originally inside resources folder) inside
> > maven
> > 'main' folder to make it work and avoid
> > 
> >     HTTP 404 - There is no Action mapped for namespace [/] and action name
> > 
> > [] associated with context path [/Hello_World_Struts2_Mvn].
> > 
> > but then struts.xml is unreachable in Netbeans project window.
> 
> You shouldn't do that ... struts.xml must lay in resource folder (it
> will be copied to WEB-INF/classes during package phase)
> 
> > I can't find the right way. I have updated libs to the latest ones.
> > struts.xml is in WEB-INF/classes in war file deployed by Netbeans (Tomcat
> > 7).
> > 
> > Bellow struts and web xmls
> > 
> > <struts>
> > 
> >     <!-- Include webwork default (from the Struts JAR). -->
> >     <include file="struts-default.xml"/>
> 
> Struts2 include this file by default, you don't have to do this (it
> can even be source of unpredictable problems)
> 
> >     <!-- Configuration for the default package. -->
> >     <package name="default" extends="struts-default">
> >     
> >         <!-- Default interceptor stack. -->
> >         <default-interceptor-ref name="paramsPrepareParamsStack"/>
> >         <action name="index"
> > 
> > class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="list">
> > 
> >             <result name="success">/WEB-INF/jsp/employees.jsp</result>
> >             <!-- we don't need the full stack here -->
> >             <interceptor-ref name="basicStack"/>
> >         
> >         </action>
> >         <action name="crud"
> > 
> > class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="input">
> > 
> >             <result name="success" type="redirectAction">index</result>
> >             <result name="input">/WEB-INF/jsp/employeeForm.jsp</result>
> >             <result name="error">/WEB-INF/jsp/error.jsp</result>
> >         
> >         </action>
> >     
> >     </package>
> > 
> > </struts>
> 
> You have two options here:
> - define action with blank name (I don't like it as this is some kind
> trick and not expected behaviour), ie.
>     <action name=""
> class="com.aurifa.struts2.tutorial.action.EmployeeAction"
> method="input">
> - define default-action-ref per package
>     <default-action-ref name="index/>
> 
> <welcome-files/> will not work as most of the containers doesn't allow
> forwarding to non-static resources, you can try to define struts2
> filter as below to achieve that:
> 
> <filter-mapping>
>         <filter-name>struts2</filter-name>
>         <url-pattern>/*</url-pattern>
>         <dispatcher>REQUEST</dispatcher>
>         <dispatcher>FORWARD</dispatcher>
>         <dispatcher>INCLUDE</dispatcher>
> </filter-mapping>
> 
> 
> Regards

Re: Actions as welcome files

Posted by Lukasz Lenart <lu...@apache.org>.
2013/5/31 Antonio Sánchez <in...@gmail.com>:
> I have to move struts.xml (originally inside resources folder) inside maven
> 'main' folder to make it work and avoid
>
>     HTTP 404 - There is no Action mapped for namespace [/] and action name
> [] associated with context path [/Hello_World_Struts2_Mvn].
>
> but then struts.xml is unreachable in Netbeans project window.

You shouldn't do that ... struts.xml must lay in resource folder (it
will be copied to WEB-INF/classes during package phase)


> I can't find the right way. I have updated libs to the latest ones.
> struts.xml is in WEB-INF/classes in war file deployed by Netbeans (Tomcat
> 7).
>
> Bellow struts and web xmls
>
> <struts>
>     <!-- Include webwork default (from the Struts JAR). -->
>     <include file="struts-default.xml"/>

Struts2 include this file by default, you don't have to do this (it
can even be source of unpredictable problems)

>     <!-- Configuration for the default package. -->
>     <package name="default" extends="struts-default">
>
>         <!-- Default interceptor stack. -->
>         <default-interceptor-ref name="paramsPrepareParamsStack"/>
>         <action name="index"
> class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="list">
>             <result name="success">/WEB-INF/jsp/employees.jsp</result>
>             <!-- we don't need the full stack here -->
>             <interceptor-ref name="basicStack"/>
>         </action>
>         <action name="crud"
> class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="input">
>             <result name="success" type="redirectAction">index</result>
>             <result name="input">/WEB-INF/jsp/employeeForm.jsp</result>
>             <result name="error">/WEB-INF/jsp/error.jsp</result>
>         </action>
>     </package>
> </struts>

You have two options here:
- define action with blank name (I don't like it as this is some kind
trick and not expected behaviour), ie.
    <action name=""
class="com.aurifa.struts2.tutorial.action.EmployeeAction"
method="input">
- define default-action-ref per package
    <default-action-ref name="index/>

<welcome-files/> will not work as most of the containers doesn't allow
forwarding to non-static resources, you can try to define struts2
filter as below to achieve that:

<filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
</filter-mapping>


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Actions as welcome files

Posted by Antonio Sánchez <in...@gmail.com>.
Is it in JIRA as feature request?

I guess I can still redirect "index.jsp" to "index.action", although it 
is not elegant, in my opinion.

Newbies are then confused because the code in the examples are using 
this feature (index.action in welcome-files), but they don't work. A 
warning would help here. I think I will post this to JIRA.

El 31/05/13 20:19, Paul Benedict escribió:
> It's not possible at the moment. It's a feature that I would like to have
> too.
>
>
> On Fri, May 31, 2013 at 1:17 PM, Antonio Sánchez <in...@gmail.com>wrote:
>
>> Hello.
>>
>> My name is Antonio, I'm beginning with Struts2 and this is my first post.
>>
>> Where should store struts.xml if I need to use an action as a welcome file?
>>
>> In example "Hello World" (maven):
>>
>> http://struts.apache.org/**development/2.x/docs/hello-**
>> world-using-struts-2.html<http://struts.apache.org/development/2.x/docs/hello-world-using-struts-2.html>
>>
>> I have to move struts.xml (originally inside resources folder) inside
>> maven 'main' folder to make it work and avoid
>>
>>      HTTP 404 - There is no Action mapped for namespace [/] and action name
>> [] associated with context path [/Hello_World_Struts2_Mvn].
>>
>> but then struts.xml is unreachable in Netbeans project window.
>>
>> In this crud example:
>>
>> http://struts.apache.org/**development/2.x/docs/hello-**
>> world-using-struts-2.html<http://struts.apache.org/development/2.x/docs/hello-world-using-struts-2.html>
>>
>> I can't find the right way. I have updated libs to the latest ones.
>> struts.xml is in WEB-INF/classes in war file deployed by Netbeans (Tomcat
>> 7).
>>
>> Bellow struts and web xmls
>>
>> <struts>
>>      <!-- Include webwork default (from the Struts JAR). -->
>>      <include file="struts-default.xml"/>
>>
>>      <!-- Configuration for the default package. -->
>>      <package name="default" extends="struts-default">
>>
>>          <!-- Default interceptor stack. -->
>>          <default-interceptor-ref name="**paramsPrepareParamsStack"/>
>>          <action name="index" class="com.aurifa.struts2.**tutorial.action.*
>> *EmployeeAction" method="list">
>>              <result name="success">/WEB-INF/jsp/**employees.jsp</result>
>>              <!-- we don't need the full stack here -->
>>              <interceptor-ref name="basicStack"/>
>>          </action>
>>          <action name="crud" class="com.aurifa.struts2.**tutorial.action.**EmployeeAction"
>> method="input">
>>              <result name="success" type="redirectAction">index</**result>
>>              <result name="input">/WEB-INF/jsp/**employeeForm.jsp</result>
>>              <result name="error">/WEB-INF/jsp/**error.jsp</result>
>>          </action>
>>      </package>
>> </struts>
>>
>>
>> <web-app>
>>      <display-name>Struts 2 Demo</display-name>
>>
>>      <welcome-file-list>
>>          <welcome-file>index.action</**welcome-file>
>>      </welcome-file-list>
>>
>>      <filter>
>>          <filter-name>struts2</filter-**name>
>> <filter-class>org.apache.**struts2.dispatcher.ng.filter.**
>> StrutsPrepareAndExecuteFilter<**/filter-class>
>>      </filter>
>>
>>      <filter-mapping>
>>          <filter-name>struts2</filter-**name>
>>          <url-pattern>/*</url-pattern>
>>      </filter-mapping>
>> </web-app>
>>
>> Thanks.
>>
>>
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Actions as welcome files

Posted by Paul Benedict <pb...@apache.org>.
It's not possible at the moment. It's a feature that I would like to have
too.


On Fri, May 31, 2013 at 1:17 PM, Antonio Sánchez <in...@gmail.com>wrote:

> Hello.
>
> My name is Antonio, I'm beginning with Struts2 and this is my first post.
>
> Where should store struts.xml if I need to use an action as a welcome file?
>
> In example "Hello World" (maven):
>
> http://struts.apache.org/**development/2.x/docs/hello-**
> world-using-struts-2.html<http://struts.apache.org/development/2.x/docs/hello-world-using-struts-2.html>
>
> I have to move struts.xml (originally inside resources folder) inside
> maven 'main' folder to make it work and avoid
>
>     HTTP 404 - There is no Action mapped for namespace [/] and action name
> [] associated with context path [/Hello_World_Struts2_Mvn].
>
> but then struts.xml is unreachable in Netbeans project window.
>
> In this crud example:
>
> http://struts.apache.org/**development/2.x/docs/hello-**
> world-using-struts-2.html<http://struts.apache.org/development/2.x/docs/hello-world-using-struts-2.html>
>
> I can't find the right way. I have updated libs to the latest ones.
> struts.xml is in WEB-INF/classes in war file deployed by Netbeans (Tomcat
> 7).
>
> Bellow struts and web xmls
>
> <struts>
>     <!-- Include webwork default (from the Struts JAR). -->
>     <include file="struts-default.xml"/>
>
>     <!-- Configuration for the default package. -->
>     <package name="default" extends="struts-default">
>
>         <!-- Default interceptor stack. -->
>         <default-interceptor-ref name="**paramsPrepareParamsStack"/>
>         <action name="index" class="com.aurifa.struts2.**tutorial.action.*
> *EmployeeAction" method="list">
>             <result name="success">/WEB-INF/jsp/**employees.jsp</result>
>             <!-- we don't need the full stack here -->
>             <interceptor-ref name="basicStack"/>
>         </action>
>         <action name="crud" class="com.aurifa.struts2.**tutorial.action.**EmployeeAction"
> method="input">
>             <result name="success" type="redirectAction">index</**result>
>             <result name="input">/WEB-INF/jsp/**employeeForm.jsp</result>
>             <result name="error">/WEB-INF/jsp/**error.jsp</result>
>         </action>
>     </package>
> </struts>
>
>
> <web-app>
>     <display-name>Struts 2 Demo</display-name>
>
>     <welcome-file-list>
>         <welcome-file>index.action</**welcome-file>
>     </welcome-file-list>
>
>     <filter>
>         <filter-name>struts2</filter-**name>
> <filter-class>org.apache.**struts2.dispatcher.ng.filter.**
> StrutsPrepareAndExecuteFilter<**/filter-class>
>     </filter>
>
>     <filter-mapping>
>         <filter-name>struts2</filter-**name>
>         <url-pattern>/*</url-pattern>
>     </filter-mapping>
> </web-app>
>
> Thanks.
>
>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Actions as welcome files

Posted by Antonio Sánchez <in...@gmail.com>.
Sorry, second link is this:

http://struts.apache.org/development/2.x/docs/crud-demo-i.html

El 31/05/13 20:17, Antonio Sánchez escribió:
> Hello.
>
> My name is Antonio, I'm beginning with Struts2 and this is my first post.
>
> Where should store struts.xml if I need to use an action as a welcome 
> file?
>
> In example "Hello World" (maven):
>
> http://struts.apache.org/development/2.x/docs/hello-world-using-struts-2.html 
>
>
> I have to move struts.xml (originally inside resources folder) inside 
> maven 'main' folder to make it work and avoid
>
>     HTTP 404 - There is no Action mapped for namespace [/] and action 
> name [] associated with context path [/Hello_World_Struts2_Mvn].
>
> but then struts.xml is unreachable in Netbeans project window.
>
> In this crud example:
>
> http://struts.apache.org/development/2.x/docs/hello-world-using-struts-2.html 
>
>
> I can't find the right way. I have updated libs to the latest ones. 
> struts.xml is in WEB-INF/classes in war file deployed by Netbeans 
> (Tomcat 7).
>
> Bellow struts and web xmls
>
> <struts>
>     <!-- Include webwork default (from the Struts JAR). -->
>     <include file="struts-default.xml"/>
>
>     <!-- Configuration for the default package. -->
>     <package name="default" extends="struts-default">
>
>         <!-- Default interceptor stack. -->
>         <default-interceptor-ref name="paramsPrepareParamsStack"/>
>         <action name="index" 
> class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="list">
>             <result name="success">/WEB-INF/jsp/employees.jsp</result>
>             <!-- we don't need the full stack here -->
>             <interceptor-ref name="basicStack"/>
>         </action>
>         <action name="crud" 
> class="com.aurifa.struts2.tutorial.action.EmployeeAction" method="input">
>             <result name="success" type="redirectAction">index</result>
>             <result name="input">/WEB-INF/jsp/employeeForm.jsp</result>
>             <result name="error">/WEB-INF/jsp/error.jsp</result>
>         </action>
>     </package>
> </struts>
>
>
> <web-app>
>     <display-name>Struts 2 Demo</display-name>
>
>     <welcome-file-list>
>         <welcome-file>index.action</welcome-file>
>     </welcome-file-list>
>
>     <filter>
>         <filter-name>struts2</filter-name>
> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
>
>     </filter>
>
>     <filter-mapping>
>         <filter-name>struts2</filter-name>
>         <url-pattern>/*</url-pattern>
>     </filter-mapping>
> </web-app>
>
> Thanks.
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org