标签: modelandview

抛出异常时不支持请求方法'POST'

我在场景中抛出异常.由哪个处理@ExceptionHandler.但是当抛出异常时,它说Request方法'POST'不支持
控制器代码

@RequestMapping(value = "abcd", method = {RequestMethod.POST,RequestMethod.GET })
public String testAbc(Model model, HttpServletRequest request) throws Exception {
    //some piece of code
    if(someCondition)
        throw new Exception("No data found with id ");
}
Run Code Online (Sandbox Code Playgroud)

ExceptionController类中的代码

@ExceptionHandler(Exception.class)
public ModelAndView handleException(Exception ex, HttpServletRequest request, HttpServletResponse response) {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("errorMessage", ex.getMessage());
    modelAndView.addObject("errorDetails", ExceptionUtils.getStackTrace(ex));
    modelAndView.setViewName("forward:errorPage");

    return modelAndView;
}
Run Code Online (Sandbox Code Playgroud)

不知道我做错了什么.

java post exception-handling spring-mvc modelandview

8
推荐指数
1
解决办法
1807
查看次数

"返回新的ModelAndView("redirect:surveys.html")之间的区别是什么;" 并"返回新的ModelAndView("surveys.html");"

问题出在标题中.我有一个Spring MVC网络应用程序,我必须修改很多东西,我对此没有任何想法,在做任何事情之前我都想了解它是如何制作的.

有什么区别:

return new ModelAndView("redirect:surveys.hmtl");
Run Code Online (Sandbox Code Playgroud)

和

return new ModelAndView("surveys.html");
Run Code Online (Sandbox Code Playgroud)

谢谢.

model-view-controller spring modelandview

7
推荐指数
1
解决办法
1万
查看次数

Spring MVC 3:在新选项卡中打开 ModelAndView

我正在jsp中提交表单。运行底层逻辑后 spring mvc 返回视图。

有2个条件。IE

if(condition1){
    mav = new ModelAndView("jspPageName1");
    return mav;
}else{
    mav = new ModelAndView("jspPageName2");
    return mav;
}
Run Code Online (Sandbox Code Playgroud)

我希望jspPageName1在新选项卡中打开,而jspPageName2将在同一选项卡中打开。

java forms jsp spring-mvc modelandview

5
推荐指数
1
解决办法
1万
查看次数

使用 Spring 在 JSP 上显示值列表

我想在我的 jsp 视图中显示我的值列表,但我不能这样做。

下面是我的控制器类,它只是将 List 添加到ModelAndView地图,然后重定向到我的index.jsp页面。

员工控制器

@Controller
public class EmployeeController {

@RequestMapping(value={"/employee"}, method = RequestMethod.GET)
public String listEmployee(){    
    System.out.println("Kontroler EmployeeController");
    LinkedList<String> list = getList();
    ModelAndView map = new ModelAndView("index");
    map.addObject("lists", list);

    return map.getViewName();
}

private LinkedList<String> getList(){
    LinkedList<String> list = new LinkedList<>();

    list.add("Item 1");
    list.add("Item 2");
    list.add("Item 3");

    return list;
}

}
Run Code Online (Sandbox Code Playgroud)

索引.jsp

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Welcome to Spring Web MVC project</title>
</head>

<body>
    <h1>Index page</h1>
    <h1>${msg}</h1>
    <a href="/MavenHello/employee">Zam?stnanci</a>
</body>
    <c:if test="${not …
Run Code Online (Sandbox Code Playgroud)

java spring jsp spring-mvc modelandview

5
推荐指数
1
解决办法
3万
查看次数

我如何在Spring RedirectView中添加对象

我是Spring的新手,我想知道如何在RedirectView中添加AddOject,就像在ModelAndView中一样,我可以添加可以在视图中使用的对象.

 mnv = new ModelAndView( FORM_URL );
        mnv.addObject( "wpassbook", passbook );
        return mnv;


RedirectView redirectView = new RedirectView( "/credit" + FORM_URL );
        return new ModelAndView( redirectView );
Run Code Online (Sandbox Code Playgroud)

无论如何,这是整个方法:

    /**
 * Accepts POST request for this resource url.
 * 
 * @param formBean bean containing values entered by the user
 * @param bindingResult contains validation failure messages if form bean is invalid
 * @param request instance of HttpServletRequest created by the container
 * @return the presentation layer & model object with errors …
Run Code Online (Sandbox Code Playgroud)

spring modelandview

3
推荐指数
1
解决办法
6817
查看次数

在我的JUnit测试中,如何验证Spring RedirectView?

我正在使用Spring 3.2.11.RELEASE和JUnit 4.11.在一个特定的Spring控制器中,我有一个方法,因此结束......

return new ModelAndView(new RedirectView(redirectUri, true));
Run Code Online (Sandbox Code Playgroud)

在我的JUnit测试中,如何验证从提交到我的控制器的返回,其中返回了此RedirectView?我以前使用org.springframework.test.web.AbstractModelAndViewTests.assertViewName,但只返回"null",即使返回非空的ModelAndView对象也是如此.这是我如何构建我的JUnit测试...

    request.setRequestURI(“/mypage/launch");
    request.setMethod("POST");
    …
   final Object handler = handlerMapping.getHandler(request).getHandler();
    final ModelAndView mav = handlerAdapter.handle(request, response,  handler);
    assertViewName(mav, "redirect:/landing");
Run Code Online (Sandbox Code Playgroud)

有关如何验证RedirectView是否返回正确值的任何帮助都是值得赞赏的,

junit spring modelandview

3
推荐指数
1
解决办法
5743
查看次数