简体   繁体   English

Spring MVC 3.0.6 @ RequestMapping用于两个级别的URL得到了404

[英]spring mvc 3.0.6 @RequestMapping for two level url got 404

I am using spring mvc 3.0.6. 我正在使用Spring MVC 3.0.6。 here is my code: 这是我的代码:

@Controller
@RequestMapping(value="/staff")
public class StaffController extends BaseController {

    @RequestMapping(method=RequestMethod.GET)
    public ModelAndView goStaffIndex(Model model) throws Exception{
        model.addAttribute("staff", new Staff());
        return new ModelAndView("staff/staffIndex","model",model);
    }

    @RequestMapping(value="/newStaff",method=RequestMethod.GET)
    public String addStaff(Model model) throws Exception{
        model.addAttribute("staff", new Staff());
        return "staff/newStaff";
        //return new ModelAndView("staff/newStaff","model",model);
    }
}
  • first method work fine. 第一种方法工作正常。

  • problem in second method, when i send a request:http://localhost:8080/mvc/staff/newStaff.do. 第二种方法的问题,当我发送请求时:http:// localhost:8080 / mvc / staff / newStaff.do。 dispatcher send request to addStaff() method, it is also fine. 调度程序向addStaff()方法发送请求,也可以。 return is also fine. 回报还可以。 because debugging message told me it fine. 因为调试消息告诉我很好。

message: 信息:

  • 20:16:30,648 INFO [stdout] DEBUG [org.springframework.web.servlet.view.JstlView] -Forwarding to resource [WEB-INF/views/staff/newStaff.jsp] in InternalResourceView 'staff/newStaff' 20:16:30,648 INFO [stdout]调试[org.springframework.web.servlet.view.JstlView]-转发到InternalResourceView'staff / newStaff'中的资源[WEB-INF / views / staff / newStaff.jsp]

  • 20:16:30,648 INFO [stdout] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request 20:16:30,648 INFO [stdout]调试[org.springframework.web.servlet.DispatcherServlet]-成功完成请求

however, page got a 404 error. 但是,页面出现404错误。 but debug console without any error or warn. 但是调试控制台没有任何错误或警告。

when i remove class @RequestMapping and change some code, such as: 当我删除类@RequestMapping并更改一些代码,例如:

public class StaffController extends BaseController {

    @RequestMapping(value="/staff",method=RequestMethod.GET)
    public ModelAndView goStaffIndex(Model model) throws Exception{
        model.addAttribute("staff", new Staff());
        return new ModelAndView("staff/staffIndex","model",model);
    }

    @RequestMapping(value="/newStaff",method=RequestMethod.GET)
    public String addStaff(Model model) throws Exception{
        model.addAttribute("staff", new Staff());
        return "staff/newStaff";
        //return new ModelAndView("staff/newStaff","model",model);
    }
}

after this, i send new request(with only one level url):http://localhost:8080/mvc/newStaff.do. 之后,我发送新请求(仅具有一个级别的URL):http:// localhost:8080 / mvc / newStaff.do。 working fine!!!! 工作正常!!! any resolution or i mistaking something? 任何决议或我误会什么?

i am using jbossAS 7.0 我正在使用jbossAS 7.0

The answer from Cristiano is almost right. 克里斯蒂亚诺的答案几乎是正确的。 The only thing that was left behind is another bar before **: 唯一留下的是**前的另一条:

@Controller
@RequestMapping(value="/staff/**")
public class StaffController extends BaseController {
...

I would add a / in front of the staff to get the application context root 我会在人员前面添加一个/以获得应用程序上下文根

try this: 尝试这个:

@Controller
@RequestMapping(value="/staff**")
public class StaffController extends BaseController {

    @RequestMapping(method=RequestMethod.GET)
    public ModelAndView goStaffIndex(Model model) throws Exception{
        model.addAttribute("staff", new Staff());
        return new ModelAndView("staff/staffIndex","model",model);
    }

    @RequestMapping(value="/staff/newStaff**",method=RequestMethod.GET)
    public String addStaff(Model model) throws Exception{
        model.addAttribute("staff", new Staff());
        return "/staff/newStaff";            
    }
}

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

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