my dog learned polymorphism*
The moose likes Other Application Frameworks and the fly likes Spring MVC problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring MVC problem" Watch "Spring MVC problem" New topic
Author

Spring MVC problem

Terril Douglas
Greenhorn

Joined: May 05, 2008
Posts: 11
Hello I have been reading SIA 2 and am currently looking at chapter 13.
I am running the example shown in the book and am getting an error.

Using Eclipse I have debugged the app and when the app reaches the controller it continously go back after I return the ModelAndView object.

here are my config files:

web.xml:<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

springmvc-servlet.xml:

<bean name="/jsp/hello_world.jsp"
class="springmvc.web.HelloWorldController" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

My controller name is HelloWorldController and is working fine. I believe the problem is with the mappings but in the book it specifies that the mapping isn't needed because there is one used by default. Can any one help?

Terril Douglas
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I think what the book means is that if you don't return a value for the View String, then it will just go back to the same page it came from. It is the default mechanism.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Terril Douglas
Greenhorn

Joined: May 05, 2008
Posts: 11
Originally posted by Mark Spritzler:
I think what the book means is that if you don't return a value for the View String, then it will just go back to the same page it came from. It is the default mechanism.

Mark


The view string is a property that goes in the Controller?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

No, the return type from a method in a Controller can return a ModelAndView object, or a String (which represents the view to forward to with a ViewResolver), or just a Model object, in which the String for the view is not set. In the case where the View string is not returned, then the default in Spring MVC is to display the same page the request came from. Well, in most cases with the default ViewResolver it will take an incoming request like "http://com.you.site/somepage.htm" then hack off the beginning part and the extension to just get "somepage" use that as the View String, then with the View Resolver prepend and append string to basically send you back to where you were.

Mark
Terril Douglas
Greenhorn

Joined: May 05, 2008
Posts: 11
Ok I understand what you are talking about and in my controller I did place the view string in the return. I will just post my Controller:

package springmvc.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
//import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class HelloWorldController extends AbstractController {
public HelloWorldController(){}

public ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

String aMessage = "Hello World MVC!";
//String lo = null;
//ModelAndView modelAndView = new ModelAndView();

return new ModelAndView("hello_world","message",aMessage);
}
}
Terril Douglas
Greenhorn

Joined: May 05, 2008
Posts: 11
Hey Mark I think the problem was that my app was going in a loop because the view was the same component that was used to refer to my bean name in the springmvc-server.xml file. So essentially when it returned from the controller the request then looked to use the view which was referring right back to the bean. Sorry for any inconvenience.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Originally posted by Terril Douglas:
Hey Mark I think the problem was that my app was going in a loop because the view was the same component that was used to refer to my bean name in the springmvc-server.xml file. So essentially when it returned from the controller the request then looked to use the view which was referring right back to the bean. Sorry for any inconvenience.


No inconvenience. That is why we are here, maybe to help, or maybe to help you find it yourself despite me.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC problem