简体   繁体   English

Spring MVC控制器映射错误(404Error)

[英]Spring mvc controller mapping error (404error)

There is a 404 error when I execute my application. 执行应用程序时出现404错误。

I can see the view when I excute first one below, but second one is not possible. 当我在下面执行第一个操作时,可以看到该视图,但是第二个操作是不可能的。

http://localhost:8091/cboard http:// localhost:8091 / cboard

http://localhost:8091/listPage http:// localhost:8091 / listPage

Please let me know what is problem. 请让我知道是什么问题。 (I need second one..) (我需要第二个。)

The controller: 控制器:

@RequestMapping("/cboard", method=RequestMethod.GET)
public String list(Model model,HttpServletRequest req) throws Exception{

   req.getSession().getAttribute("clientMemberVO");
   model.addAttribute("list", service.listAll());
   List<BoardVO> list = service.listCriteria(cri);


    return "/cboard/titlelist";
}

@RequestMapping("/listPage", method=RequestMethod.GET)   
    public String listPage(Model model, Criteria cri, HttpServletRequest 
    req) throws Exception{
        req.getSession().getAttribute("clientMemberVO");

    List<CustomerBoardVO> list = service.listCriteria(cri);

    model.addAttribute("list", list); 

       PageMaker maker = new PageMaker();
          maker.setCri(cri);
          maker.setTotalCount(service.countPaging());

    model.addAttribute("pageMaker", maker);
    return "/cboard/titlelist";
}

There was an error in the code and its not properly build I guess. 代码中有一个错误,我想它的构建不正确。 since in the second method, the model and req objects are not found in parameters , but inside that listPage method its been used. 因为在第二种方法中,在parameter中找不到model和req对象,但是在该listPage方法中使用了它。 That is a compilation issue. 那是一个编译问题。

Please check the code again and its build properly. 请再次检查代码并正确构建。

What is your server name ? 您的server name什么? And maybe you are not very clear the composition of the URL, like scheme://host:port/path?query . 也许您不太清楚URL的组成,例如scheme://host:port/path?query I want you to know that path including the server name and other parts. 我希望您知道该path包括server name和其他部分。 "/listPage", "/cboard" in your controller are all belong to other parts . 控制器中的"/listPage", "/cboard"都属于other parts But the url you want to visit is http://localhost:8091/cboard , if you sure it could be visited, I guess your server name is 'cboard'. 但是您要访问的URL是http://localhost:8091/cboard ,如果您确定可以访问,则我猜您的服务器名称为'cboard'。 In this case if you want visit /listPage , you should visit http://localhost:8091/cboard/listPage ,you can have a try~ 在这种情况下,如果您想访问/listPage ,则应该访问http://localhost:8091/cboard/listPage ,可以尝试一下〜
ps: If you are clear on the composition of the URL, you might be very easy to solve such problems as 404 ps:如果您清楚URL的组成,则可能很容易解决404之类的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM