Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can one JSP be matched to different Action classes ?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application looks like

In the first page it asks you to choose if you're a

a) new student
b) old student
c) part time student

Then

if you are "new student" you go through "Registrtion.jsp" -->"OpenAccount.jsp"-->"Course.jsp"

if you're old student, you go thorough "Registration.jsp"-->"Course.jsp"

if you're part time, go through "Registration.jsp"-->"CreditHour.jsp"

I want to create and maintain as few JSP as possible. SO, for "Registration.jsp" page it has 3 possible destinations.
I decide to use 3 different "DispathAction" classes for three student types. So I will create the following mapping:

<action path="/newStudent" type="org.apache.struts.actions.DispatchAction"
name="RegistrationBean", input="/registration.jsp">
<forward name="success" path="/OpenAccount.jsp"/>

<action path="/oldStudent" type="org.apache.struts.actions.DispatchAction"
name="RegistrationBean", input="/registration.jsp">
<forward name="success" path="/Course.jsp"/>

<action path="/partTime" type="org.apache.struts.actions.DispatchAction"
name="RegistrationBean" input="/registration.jsp">
<forward name="sccess" path="/CreaditHour.jsp"/>

This way, given a "Registration.jsp" I have 3 different destinations by calling three different "path" in action. Does this make sense ?
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
multiple action mappings can be forwarded to 1 jsp.

as written, you're missing the 'parameter' attribute in your action mappings, which is required for DispatchAction to work.

if i were you, i wouldn't use DispatchAction for this since the scenario is rather basic struts. i'd have:

1. <action path="/registration/choose" forward="selectStudentType.jsp"/>
. the jsp would contain a form mapped to

2. <action path="/registration/select" name="RegistrationBean" type="com.my.actions.SelectAction">
<forward name="newStudent" path="OpenAccount.jsp"/>
<forward name="oldStudent" path="Course.jsp"/>
<forward name="partTime" path="CreditHour.jsp"/>
</action>
. RegistrationBean would contain a 'studentType' form-property (in addition to other registration form-properties or you can also use a separate bean).
. the radio button would have the 3 forward names as choices (html:radio name="studentType" value="newStudent" etc.)

3. SelectionAction.execute() would look at the 'studentType' value and findFoward to the value of the 'studentType'
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic