Results 1 to 4 of 4

Thread: forward alias.

  1. #1
    Join Date
    Nov 2004
    Location
    Russia, Moscow
    Posts
    3

    Default forward alias.

    Hello to All!!
    Please suggest me how I can give an alias to forward path in struts manner. I mean:
    in struts we write
    Code:
    <action path="/process/login" type="com.my.site....">
       <forward name="success" path="/jsp/login.jsp"/>
    </action>
    As you can see the "success" name is alias of "/jsp/login.jsp" path. In spring we use viewResolver:
    Code:
    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="prefix"><value>/WEB-INF/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
    </bean>
    As you know a real name of jsp file we need point in action class. I think it doesn't good idea, that's why I want to do it like in struts. How can I do it?
    I tried to use something like that:
    Code:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
    		<property name="location"><value>/WEB-INF/views.xml</value></property>
    	</bean>
    but didn't understand what must be in view.xml file. Can anybody show me example?
    Thank you for your responses!

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    View XML simply contains the bean definitions for the view objects:

    Code:
    <bean id="parent" abstract="true" class="org.springframework.web.servlet.view.JstlView"/>
    
    <bean id="success" parent="paren">
      <property name="url"><value>/WEB-INF/jsp/login.jsp</value></property>
    </bean>
    
    <bean id="failure" parent="parent">
      <property name="url"><value>/WEB-INF/jsp/login.jsp</value></property>
    </bean>
    As you can see this uses the parent feature of the BeanFactory to limit the amount of times you have to type the class name...

    The same thing by the way can be done in the ResourceBundleViewResolver. It works alsmost the same, except for the view beans being defined in properties files instead of Spring XML format. More info can be found in the refernece manual and the ResourceBundleViewResolver's JavaDoc.

    regards,
    Alef
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Nov 2004
    Location
    Russia, Moscow
    Posts
    3

    Default

    Alef Arendsen, thanks for your help!

  4. #4
    Join Date
    Nov 2004
    Location
    Russia, Moscow
    Posts
    3

    Default

    Hello Alef!
    I have tried you solution. This is what I need. But in your example forward alias looks like a global forward name:

    Code:
    <bean id="success" parent="paren"> 
      <property name="url"><value>/WEB-INF/jsp/login.jsp</value></property> 
    </bean>
    Do you know how to define local forwards for an action? I mean, for ex., I 've got "LOGIN" action which has its own "success" and "failure" farwards and I've got "LOGOUT" action with its own "success" and "failure" farwards as well. how to resolve such a case?

Similar Threads

  1. View to forward to another controller?
    By justinp in forum Web
    Replies: 6
    Last Post: Apr 2nd, 2010, 01:53 PM
  2. Replies: 1
    Last Post: Oct 21st, 2005, 05:27 AM
  3. Replies: 3
    Last Post: Sep 22nd, 2005, 10:14 AM
  4. Replies: 3
    Last Post: Apr 28th, 2005, 02:27 AM
  5. The forward: feature
    By eisenb in forum Web
    Replies: 0
    Last Post: Dec 13th, 2004, 03:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •