Circular view path [login3]: would dispatch back to the current handler URL [/Spring_Demo/login3]

    最近在学习使用springmvc,遇到了不少的坑,刚刚就遇到了一个,遂记录之

这是一段非常简单的代码,通过lhttp://localhost:8080/Spring_Demo/login3来访问,由前端控制器分发到这里来处理请求,本应该正常跳转的,但是遇到了bug

package fkit.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;

import fkit.domain.User;

@Controller
public class User3Controller {

	private static final Log logger = LogFactory.getLog(User3Controller.class);

	@ModelAttribute
	public void userModel3(String loginname, String password, ModelAndView mv) {
		logger.info("userModel3");
		User user = new User();
		user.setLoginname(loginname);
		user.setPassword(password);
		mv.addObject("user", user);
	}

	@RequestMapping(value = "/login3")
	public ModelAndView login3(ModelAndView mv) {
		User user = (User) mv.getModel().get("user");
		user.setUsername("张三");
		System.out.println(user);
		mv.setViewName("/WEB-INF/content/result3.jsp");
		return mv;
	}

}


以下是错误信息

HTTP Status 500 - Circular view path [login3]: would dispatch back to the current handler URL [/Spring_Demo/login3] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

type Exception report

message Circular view path [login3]: would dispatch back to the current handler URL [/Spring_Demo/login3] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Circular view path [login3]: would dispatch back to the current handler URL [/Spring_Demo/login3] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
	org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:205)
	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:145)
	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282)
	org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

note The full stack trace of the root cause is available in the Apache Tomcat/8.0.39 logs.


    怎么也想不通为什么会是路径回环错误,经过仔细排查,发现是import org.springframework.web.portlet.ModelAndView;有问题,本应该是import org.springframework.web.servlet.ModelAndView;


你可能感兴趣的:(java)