You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Burton Rhodes <bu...@gmail.com> on 2010/04/14 23:22:46 UTC

[S2] Welcome Page as Action?

I'm sure this answer is trivial, but I can't figure how to do a
server-side forward to a Struts action from my welcome page
(index.jsp).  Currently I have index.jsp "redirecting" the user, but I
would like to eliminate the roundtrip that a "redirect" imposes (I've
had complaints from mobile users).  All my "forward" attempts give a
RequestURL file not found error.  Has anyone done this?  Google seems
to be unhelpful.

Currently this works but makes a roundtrip (index.jsp) :
<% response.sendRedirect("Login_show.action"); %>

Serverside attempts without success (index.jsp):
<jsp:forward page="Login_show.action"/>
<jsp:forward page="/Login_show.action"/>
<jsp:forward page="Login_show"/>

Using:
Struts 2.1.8
Tomcat 6.x
Apache 2.2

Many Thanks,
Burton

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


Re: [S2] Welcome Page as Action?

Posted by Chris Pratt <th...@gmail.com>.
The problem is that many servlet containers won't even execute the filter
chain unless there's a match.  And http://www.domain.com/path doesn't
inherently match index.html.  So it looks to see if there is a file matching
the <welcome-file> ready to be dispatched.  If so it starts the chain and
the filters get executed as you said.  But without that empty file, many
servlet containers won't even get to the filter chain.
  (*Chris*)

On Wed, Apr 14, 2010 at 10:31 PM, Brian Thompson <el...@gmail.com>wrote:

> Struts runs in a filter that applies to requests that come through, so
> the welcome file in web.xml doesn't matter.
>
> -Brian
>
> On Wed, Apr 14, 2010 at 9:21 PM, Krunal Dhamelia <nk...@gmail.com>
> wrote:
> > I want to do the same thing but I didn't get you clear Brian.
> > If we follow your solution then Could you please explain little in brief
> > that how web.xml know about struts default action?
> > What should we put in web.xml for welcome file?
> >
> > Krunal Dhamelia
> >
> >
> > On Wed, Apr 14, 2010 at 6:00 PM, Brian Thompson <elephantium@gmail.com
> >wrote:
> >
> >> On Wed, Apr 14, 2010 at 4:22 PM, Burton Rhodes <bu...@gmail.com>
> >> wrote:
> >> > I'm sure this answer is trivial, but I can't figure how to do a
> >> > server-side forward to a Struts action from my welcome page
> >> > (index.jsp).  Currently I have index.jsp "redirecting" the user, but I
> >> > would like to eliminate the roundtrip that a "redirect" imposes (I've
> >> > had complaints from mobile users).  All my "forward" attempts give a
> >> > RequestURL file not found error.  Has anyone done this?  Google seems
> >> > to be unhelpful.
> >> >
> >>
> >>
> >> Add a default action in your struts xml.  It's what we're doing in our
> >> Struts app where I work.
> >>
> >> <package name="foo">
> >>  <default-action-ref name="welcome"/>
> >>  <action name="welcome" class="com.example.WelcomeAction">
> >>    <result name="success">welcome.jsp</result>
> >>  </action>
> >> </package>
> >>
> >> -Brian
> >>
> >>
> >>
> >> > Currently this works but makes a roundtrip (index.jsp) :
> >> > <% response.sendRedirect("Login_show.action"); %>
> >> >
> >> > Serverside attempts without success (index.jsp):
> >> > <jsp:forward page="Login_show.action"/>
> >> > <jsp:forward page="/Login_show.action"/>
> >> > <jsp:forward page="Login_show"/>
> >> >
> >> > Using:
> >> > Struts 2.1.8
> >> > Tomcat 6.x
> >> > Apache 2.2
> >> >
> >> > Many Thanks,
> >> > Burton
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@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: [S2] Welcome Page as Action?

Posted by Burton Rhodes <bu...@gmail.com>.
Haven't gotten it to work just yet.  Just one of those minor
enhancements that you can't justify spending an entire day on.  I'll
keep woroking at it though.  Thanks all for your input and knowledge.

On Thu, Apr 15, 2010 at 3:59 AM, Upasana Sharma <sh...@gmail.com> wrote:
> Hi
>
> I put these in my project and its working for me.
>
> I created a blank file called welcome.
>
> In struts.xml
>
> <package name="default" namespace="/" extends="struts-default">
> <default-action-ref name="welcome"/>
>  <action name="welcome" class="com.upasana.WelcomeAction">
>  <result name="SUCCESS">WelcomePage.jsp</result>
> </action>
> </package>
>
> In web.xml
>
> <welcome-file-list>
> <welcome-file>welcome</welcome-file>
> </welcome-file-list>
>
> Thanks and Regards
> Upasana Sharma
> <http://www.mydomain.com/package/DOESNOTEXIST.action>
>

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


Re: [S2] Welcome Page as Action?

Posted by Upasana Sharma <sh...@gmail.com>.
Hi

I put these in my project and its working for me.

I created a blank file called welcome.

In struts.xml

<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="welcome"/>
  <action name="welcome" class="com.upasana.WelcomeAction">
  <result name="SUCCESS">WelcomePage.jsp</result>
</action>
</package>

In web.xml

<welcome-file-list>
<welcome-file>welcome</welcome-file>
</welcome-file-list>

Thanks and Regards
Upasana Sharma
<http://www.mydomain.com/package/DOESNOTEXIST.action>

Re: [S2] Welcome Page as Action?

Posted by Chris Pratt <th...@gmail.com>.
How'd it go when you put an empty default.action file in the directory?
  (*Chris*)

On Wed, Apr 14, 2010 at 10:54 PM, Burton Rhodes <bu...@gmail.com>wrote:

> I'm not sure the default action solves the problem.
>
> I am put this in my struts.xml file:
> <!--  Set the default action to Login_show -->
> <default-action-ref name="Login_show" />
>
> It appears that it only loads Login_show if a user types in an
> *.action file.  For example:
>
> URL: http://www.mydomain.com/package/DOESNOTEXIST.action
> Result: http://www.mydomain.com/package/Login_show.action
>
> URL: http://www.mydomain.com/package/
> Result: Simply loads the index.jsp file (I believe it doesn't route
> through Struts because it doesn't match a "url-pattern" for the struts
> filter). And if I put a <jsp:forward name="Login_show.action"/> in
> index.jsp - I still get URL not found as before.
>
> How are you getting the user from www.mydomain.com ->
> www.mydomain.com/package/default.action using this method?  I think I
> am missing a step.
>
>
> On Thu, Apr 15, 2010 at 12:31 AM, Brian Thompson <el...@gmail.com>
> wrote:
> > Struts runs in a filter that applies to requests that come through, so
> > the welcome file in web.xml doesn't matter.
> >
> > -Brian
> >
> > On Wed, Apr 14, 2010 at 9:21 PM, Krunal Dhamelia <nk...@gmail.com>
> wrote:
> >> I want to do the same thing but I didn't get you clear Brian.
> >> If we follow your solution then Could you please explain little in brief
> >> that how web.xml know about struts default action?
> >> What should we put in web.xml for welcome file?
> >>
> >> Krunal Dhamelia
> >>
> >>
> >> On Wed, Apr 14, 2010 at 6:00 PM, Brian Thompson <elephantium@gmail.com
> >wrote:
> >>
> >>> On Wed, Apr 14, 2010 at 4:22 PM, Burton Rhodes <burtonrhodes@gmail.com
> >
> >>> wrote:
> >>> > I'm sure this answer is trivial, but I can't figure how to do a
> >>> > server-side forward to a Struts action from my welcome page
> >>> > (index.jsp).  Currently I have index.jsp "redirecting" the user, but
> I
> >>> > would like to eliminate the roundtrip that a "redirect" imposes (I've
> >>> > had complaints from mobile users).  All my "forward" attempts give a
> >>> > RequestURL file not found error.  Has anyone done this?  Google seems
> >>> > to be unhelpful.
> >>> >
> >>>
> >>>
> >>> Add a default action in your struts xml.  It's what we're doing in our
> >>> Struts app where I work.
> >>>
> >>> <package name="foo">
> >>>  <default-action-ref name="welcome"/>
> >>>  <action name="welcome" class="com.example.WelcomeAction">
> >>>    <result name="success">welcome.jsp</result>
> >>>  </action>
> >>> </package>
> >>>
> >>> -Brian
> >>>
> >>>
> >>>
> >>> > Currently this works but makes a roundtrip (index.jsp) :
> >>> > <% response.sendRedirect("Login_show.action"); %>
> >>> >
> >>> > Serverside attempts without success (index.jsp):
> >>> > <jsp:forward page="Login_show.action"/>
> >>> > <jsp:forward page="/Login_show.action"/>
> >>> > <jsp:forward page="Login_show"/>
> >>> >
> >>> > Using:
> >>> > Struts 2.1.8
> >>> > Tomcat 6.x
> >>> > Apache 2.2
> >>> >
> >>> > Many Thanks,
> >>> > Burton
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: user-unsubscribe@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
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Welcome Page as Action?

Posted by Burton Rhodes <bu...@gmail.com>.
I'm not sure the default action solves the problem.

I am put this in my struts.xml file:
<!--  Set the default action to Login_show -->
<default-action-ref name="Login_show" />

It appears that it only loads Login_show if a user types in an
*.action file.  For example:

URL: http://www.mydomain.com/package/DOESNOTEXIST.action
Result: http://www.mydomain.com/package/Login_show.action

URL: http://www.mydomain.com/package/
Result: Simply loads the index.jsp file (I believe it doesn't route
through Struts because it doesn't match a "url-pattern" for the struts
filter). And if I put a <jsp:forward name="Login_show.action"/> in
index.jsp - I still get URL not found as before.

How are you getting the user from www.mydomain.com ->
www.mydomain.com/package/default.action using this method?  I think I
am missing a step.


On Thu, Apr 15, 2010 at 12:31 AM, Brian Thompson <el...@gmail.com> wrote:
> Struts runs in a filter that applies to requests that come through, so
> the welcome file in web.xml doesn't matter.
>
> -Brian
>
> On Wed, Apr 14, 2010 at 9:21 PM, Krunal Dhamelia <nk...@gmail.com> wrote:
>> I want to do the same thing but I didn't get you clear Brian.
>> If we follow your solution then Could you please explain little in brief
>> that how web.xml know about struts default action?
>> What should we put in web.xml for welcome file?
>>
>> Krunal Dhamelia
>>
>>
>> On Wed, Apr 14, 2010 at 6:00 PM, Brian Thompson <el...@gmail.com>wrote:
>>
>>> On Wed, Apr 14, 2010 at 4:22 PM, Burton Rhodes <bu...@gmail.com>
>>> wrote:
>>> > I'm sure this answer is trivial, but I can't figure how to do a
>>> > server-side forward to a Struts action from my welcome page
>>> > (index.jsp).  Currently I have index.jsp "redirecting" the user, but I
>>> > would like to eliminate the roundtrip that a "redirect" imposes (I've
>>> > had complaints from mobile users).  All my "forward" attempts give a
>>> > RequestURL file not found error.  Has anyone done this?  Google seems
>>> > to be unhelpful.
>>> >
>>>
>>>
>>> Add a default action in your struts xml.  It's what we're doing in our
>>> Struts app where I work.
>>>
>>> <package name="foo">
>>>  <default-action-ref name="welcome"/>
>>>  <action name="welcome" class="com.example.WelcomeAction">
>>>    <result name="success">welcome.jsp</result>
>>>  </action>
>>> </package>
>>>
>>> -Brian
>>>
>>>
>>>
>>> > Currently this works but makes a roundtrip (index.jsp) :
>>> > <% response.sendRedirect("Login_show.action"); %>
>>> >
>>> > Serverside attempts without success (index.jsp):
>>> > <jsp:forward page="Login_show.action"/>
>>> > <jsp:forward page="/Login_show.action"/>
>>> > <jsp:forward page="Login_show"/>
>>> >
>>> > Using:
>>> > Struts 2.1.8
>>> > Tomcat 6.x
>>> > Apache 2.2
>>> >
>>> > Many Thanks,
>>> > Burton
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@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
>
>

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


Re: [S2] Welcome Page as Action?

Posted by Brian Thompson <el...@gmail.com>.
Struts runs in a filter that applies to requests that come through, so
the welcome file in web.xml doesn't matter.

-Brian

On Wed, Apr 14, 2010 at 9:21 PM, Krunal Dhamelia <nk...@gmail.com> wrote:
> I want to do the same thing but I didn't get you clear Brian.
> If we follow your solution then Could you please explain little in brief
> that how web.xml know about struts default action?
> What should we put in web.xml for welcome file?
>
> Krunal Dhamelia
>
>
> On Wed, Apr 14, 2010 at 6:00 PM, Brian Thompson <el...@gmail.com>wrote:
>
>> On Wed, Apr 14, 2010 at 4:22 PM, Burton Rhodes <bu...@gmail.com>
>> wrote:
>> > I'm sure this answer is trivial, but I can't figure how to do a
>> > server-side forward to a Struts action from my welcome page
>> > (index.jsp).  Currently I have index.jsp "redirecting" the user, but I
>> > would like to eliminate the roundtrip that a "redirect" imposes (I've
>> > had complaints from mobile users).  All my "forward" attempts give a
>> > RequestURL file not found error.  Has anyone done this?  Google seems
>> > to be unhelpful.
>> >
>>
>>
>> Add a default action in your struts xml.  It's what we're doing in our
>> Struts app where I work.
>>
>> <package name="foo">
>>  <default-action-ref name="welcome"/>
>>  <action name="welcome" class="com.example.WelcomeAction">
>>    <result name="success">welcome.jsp</result>
>>  </action>
>> </package>
>>
>> -Brian
>>
>>
>>
>> > Currently this works but makes a roundtrip (index.jsp) :
>> > <% response.sendRedirect("Login_show.action"); %>
>> >
>> > Serverside attempts without success (index.jsp):
>> > <jsp:forward page="Login_show.action"/>
>> > <jsp:forward page="/Login_show.action"/>
>> > <jsp:forward page="Login_show"/>
>> >
>> > Using:
>> > Struts 2.1.8
>> > Tomcat 6.x
>> > Apache 2.2
>> >
>> > Many Thanks,
>> > Burton
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@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: [S2] Welcome Page as Action?

Posted by Krunal Dhamelia <nk...@gmail.com>.
I want to do the same thing but I didn't get you clear Brian.
If we follow your solution then Could you please explain little in brief
that how web.xml know about struts default action?
What should we put in web.xml for welcome file?

Krunal Dhamelia


On Wed, Apr 14, 2010 at 6:00 PM, Brian Thompson <el...@gmail.com>wrote:

> On Wed, Apr 14, 2010 at 4:22 PM, Burton Rhodes <bu...@gmail.com>
> wrote:
> > I'm sure this answer is trivial, but I can't figure how to do a
> > server-side forward to a Struts action from my welcome page
> > (index.jsp).  Currently I have index.jsp "redirecting" the user, but I
> > would like to eliminate the roundtrip that a "redirect" imposes (I've
> > had complaints from mobile users).  All my "forward" attempts give a
> > RequestURL file not found error.  Has anyone done this?  Google seems
> > to be unhelpful.
> >
>
>
> Add a default action in your struts xml.  It's what we're doing in our
> Struts app where I work.
>
> <package name="foo">
>  <default-action-ref name="welcome"/>
>  <action name="welcome" class="com.example.WelcomeAction">
>    <result name="success">welcome.jsp</result>
>  </action>
> </package>
>
> -Brian
>
>
>
> > Currently this works but makes a roundtrip (index.jsp) :
> > <% response.sendRedirect("Login_show.action"); %>
> >
> > Serverside attempts without success (index.jsp):
> > <jsp:forward page="Login_show.action"/>
> > <jsp:forward page="/Login_show.action"/>
> > <jsp:forward page="Login_show"/>
> >
> > Using:
> > Struts 2.1.8
> > Tomcat 6.x
> > Apache 2.2
> >
> > Many Thanks,
> > Burton
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Welcome Page as Action?

Posted by Brian Thompson <el...@gmail.com>.
On Wed, Apr 14, 2010 at 4:22 PM, Burton Rhodes <bu...@gmail.com> wrote:
> I'm sure this answer is trivial, but I can't figure how to do a
> server-side forward to a Struts action from my welcome page
> (index.jsp).  Currently I have index.jsp "redirecting" the user, but I
> would like to eliminate the roundtrip that a "redirect" imposes (I've
> had complaints from mobile users).  All my "forward" attempts give a
> RequestURL file not found error.  Has anyone done this?  Google seems
> to be unhelpful.
>


Add a default action in your struts xml.  It's what we're doing in our
Struts app where I work.

<package name="foo">
  <default-action-ref name="welcome"/>
  <action name="welcome" class="com.example.WelcomeAction">
    <result name="success">welcome.jsp</result>
  </action>
</package>

-Brian



> Currently this works but makes a roundtrip (index.jsp) :
> <% response.sendRedirect("Login_show.action"); %>
>
> Serverside attempts without success (index.jsp):
> <jsp:forward page="Login_show.action"/>
> <jsp:forward page="/Login_show.action"/>
> <jsp:forward page="Login_show"/>
>
> Using:
> Struts 2.1.8
> Tomcat 6.x
> Apache 2.2
>
> Many Thanks,
> Burton

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


Re: [S2] Welcome Page as Action?

Posted by Chris Pratt <th...@gmail.com>.
I'm not sure if this will work everywhere, but it works in Resin.   If
you set your <welcome-file> to index.action and put an empty (ie 0
length) file named index.action in the root directory of your war
file.  When the server gets the request, it first checks to see if the
request matches a known resource, if not it checks the directory for a
file matching specified welcome-file. If it finds one, things proceed
as usual and struts gets the request to process and will naturally go
to your index.jsp file to fulfil the request.
  (*Chris*)

On Wednesday, April 14, 2010, Burton Rhodes <bu...@gmail.com> wrote:
> I'm sure this answer is trivial, but I can't figure how to do a
> server-side forward to a Struts action from my welcome page
> (index.jsp).  Currently I have index.jsp "redirecting" the user, but I
> would like to eliminate the roundtrip that a "redirect" imposes (I've
> had complaints from mobile users).  All my "forward" attempts give a
> RequestURL file not found error.  Has anyone done this?  Google seems
> to be unhelpful.
>
> Currently this works but makes a roundtrip (index.jsp) :
> <% response.sendRedirect("Login_show.action"); %>
>
> Serverside attempts without success (index.jsp):
> <jsp:forward page="Login_show.action"/>
> <jsp:forward page="/Login_show.action"/>
> <jsp:forward page="Login_show"/>
>
> Using:
> Struts 2.1.8
> Tomcat 6.x
> Apache 2.2
>
> Many Thanks,
> Burton
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@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