Announcement Announcement Module
Collapse
No announcement yet.
View resolver not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • View resolver not working

    Code:
    public class AuthenticateController extends SimpleFormController
    {
    
        public ModelAndView onSubmit(javax.servlet.http.HttpServletRequest request,
                javax.servlet.http.HttpServletResponse response,
                java.lang.Object command, BindException errors)
                throws java.lang.Exception
        {
    
    
            return new ModelAndView(new RedirectView(getSuccessView()));
    
        }
    The above code shows following URL:
    http://localhost:8080/ERSpring/loggedin
    in stead of
    http://localhost:8080/ERSpring/view/...t/loggedin.jsp

    Here is my veiwResolver mapping.
    Code:
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass">
    			<value>org.springframework.web.servlet.view.JstlView</value>
    		</property>
    		<property name="prefix">
    			<value>/views/patient/</value>
    		</property>
    		<property name="suffix">
    			<value>.jsp</value>
    		</property>
    	</bean>
    If I use
    Code:
    public void doSubmitAction&#40;Object command&#41; throws ServletException
    everything works fine. But it doesn't work for onSubmit.

    What am I missing here? I am using spring 1.1

  • #2
    Sorry I missed out the controller.

    Code:
    	<bean id="authenticateController"
    		class="controller.AuthenticateController">
    		<property name="sessionForm">
    			<value>true</value>
    		</property>
    		<property name="commandName">
    			<value>authenticate</value>
    		</property>
    		<property name="commandClass">
    			<value>hibernate.patient.Authenticate</value>
    		</property>
    		<property name="validator">
    			<ref bean="AuthenticateValidator" />
    		</property>
    		<property name="formView">
    			<value>login</value>
    		</property>
    		<property name="successView">
    			<value>loggedin</value>
    		</property>
    	</bean>

    Comment


    • #3
      Could you post your handler mapping as well if you have one?

      Comment


      • #4
        Things work fine if I don't use redirect.
        Code:
        return new ModelAndView&#40;getSuccessView&#40;&#41;&#41;;  //works
        return new ModelAndView&#40;new RedirectView&#40;getSuccessView&#40;&#41;&#41;&#41;; //does not work
        Could someone explain to me what "redirect" does? Is it similar to 'redirect=true' in struts?

        Here is handler mapping.
        Code:
        	<bean id="urlMapping"
        		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        		<property name="mappings">
        			<props>
        				<prop key="/login.htm">authenticateController</prop>
        			</props>
        		</property>
        	</bean>
        Thanks.
        - Simon

        Comment


        • #5
          Here is the flow for your app.

          1) User visits http://yourserverurl/ERSpring/login.htm (Assuming ERSpring your servlet context path) and submits the form.
          2) Gets it request handed over to the controller.
          3) Controller does it's stuff and does one of two
          3a) return new ModelAndView(getSuccessView()). This will actually look for a resource in you web application for (prefix+viewName+suffix), which is in your case /views/patient/loggedin.jsp and renders it. This does not mean it will show that url in the url window for the browser.
          3b) return new ModelAndView(new RedirectView(getSuccessView())). This will redirect (Yes it is similar to redirect in struts but has more power). It will actually redirect you to http://yourserverurl/loggedin. I am a little surprised that you still see the context path. Can you verify that for sure?

          Comment


          • #6
            Verification:

            3a) You are right. I get the new view but the top url doesn't change. Similar to redirect=false in struts.
            3b) I get following URL. exact cut-n-paste. http://localhost:8080/ERSpring/loggedin


            I have seen spring examples using redirect view. I'm not sure why it's not working for me. I also tried usingn spring 1.1.4; no success.

            Comment


            • #7
              3b) Do you have anything configured for that url? Does not look like you have anything mapped to that url in spring url mapping handler. Do you have any resource in the root of your webapplication called "loggedin"? If not the behaviour is expected.

              May be I am missing the point but it seems like it is behaving like it should.

              Comment


              • #8
                I was expecting that before the URL is formed the jsp name would be resolved using the resolver.

                For now I would just like to know the utility of *redirect*.

                - Simon

                Comment


                • #9
                  All it does is sends a redirect to the browser, just like struts

                  Comment


                  • #10
                    Model -&gt; GET params

                    Although I would have to double check with the documentation, I am almost certian that a RedirectView will place all of your model variables into the query string so you can use them as parameters, based on the names used in the Map. I believe Struts does this as well using the ActionForm but I could be wrong.

                    Comment

                    Working...
                    X