Results 1 to 3 of 3

Thread: URL request

  1. #1

    Cool URL request

    Is this necessary that every URL request must by preceeded with some controller?
    When I use org.springframework.web.servlet.handler.SimpleUrlH andlerMapping

    HTML Code:
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    	<property name="mappings">
    		<props>
    			<prop key="/login.html">loginController</prop>
    		</props>
    	</property>	
    	</bean>
    there must be always some controller ( like loginController ). How to proceed request directly to some html file (without view resolver etc.).

  2. #2
    Join Date
    Aug 2004
    Location
    San Francisco, CA
    Posts
    66

    Default

    You can use a org.springframework.web.servlet.mvc.Parameterizabl eViewController which takes a single property, the view name. Example:

    Code:
    <bean id="userUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/login.html">loginController</prop>
            </props>
        </property>
    </bean>
    
    <bean id="loginController" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
        <property name="viewName" value="login" />
    </bean>
    That will render the view with the named loginPage. How that view is resolved depends on your view resolver. Typically, that's a ResourceBundleViewResolver, a UrlBasedViewResolver, or BeanNameViewResolver. The latter being the simplest for little apps. The former are more realistic for any normal application.

    An example of the UrlBasedViewResolver might look like:

    Code:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
    </bean>
    This will look for a page called login.jsp in the directory /WEB-INF/jsp and render it.

    If you go directly to some page without going through the controller, you're bypassing the whole MVC framework. For entirely static pages, this might be okay. For anything that's dynamic, it's probably a Bad Idea. The controller should fetch the model from wherever (usually the service layer), and pass it to the view for rendering. You'll find out more about this if you search for "web mvc" or "web model 2".

    Christian

  3. #3

    Thumbs up

    Quote Originally Posted by cnelson
    You can use a org.springframework.web.servlet.mvc.Parameterizabl eViewController which takes a single property, the view name. Example:

    Code:
    <bean id="userUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/login.html">loginController</prop>
            </props>
        </property>
    </bean>
    
    <bean id="loginController" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
        <property name="viewName" value="login" />
    </bean>
    That will render the view with the named loginPage. How that view is resolved depends on your view resolver. Typically, that's a ResourceBundleViewResolver, a UrlBasedViewResolver, or BeanNameViewResolver. The latter being the simplest for little apps. The former are more realistic for any normal application.

    An example of the UrlBasedViewResolver might look like:

    Code:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
    </bean>
    This will look for a page called login.jsp in the directory /WEB-INF/jsp and render it.

    If you go directly to some page without going through the controller, you're bypassing the whole MVC framework. For entirely static pages, this might be okay. For anything that's dynamic, it's probably a Bad Idea. The controller should fetch the model from wherever (usually the service layer), and pass it to the view for rendering. You'll find out more about this if you search for "web mvc" or "web model 2".

    Christian
    I need this just for entirely static page, so that's why I've been asking about it. Thanks for help.

Posting Permissions

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