gpt4 book ai didi

jsp - 从 JSP 重定向到 Controller Spring

转载 作者:行者123 更新时间:2023-12-02 04:53:07 24 4
gpt4 key购买 nike

我有一个 JSP,我想在单击 URL 时用来调用 Controller (链接到另一个 JSP 页面),我的代码如下:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<h1>Spring MVC Hello World Example</h1>

<h2>${msg}</h2>

<a href="/FileMonitor/ResultPage/">click</a>

</body>
</html>

我想在/FileMonitor/ResultPage/调用的类在这里:

@Controller
@RequestMapping(value="/Result")
public class ResultController extends AbstractController {

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {

ModelAndView model = new ModelAndView("ResultPage");
model.addObject("msg", "result");

return model;
}

}

但是我遇到了 404,有人能看出我做错了什么吗?如何从 JSP 页面访问 Controller ?

最佳答案

@Controller
@RequestMapping(value="/FileMonitor/ResultPage/")
public class ResultController extends AbstractController {

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {

ModelAndView model = new ModelAndView("ResultPage");
model.addObject("msg", "result");

return model;
}

}

关于jsp - 从 JSP 重定向到 Controller Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18488625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com