企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 默认行为 ~~~ @RequestMapping(path = "/ok") public void testResponse() { System.out.println("hello"); } ~~~ 里面的方法执行了,但是页面报错404.并且默认的寻找的页面是注解配置的路径名. ![](https://box.kancloud.cn/a3dc8c1c2d7a63ed223f70398ec8bd89_1646x330.png) ## 请求转发 ~~~ @RequestMapping(path = "/ok") public void testResponse(HttpServletRequest request, HttpServletResponse response) throws Exception { //编写请求转发的程序.请求转发是一次请求,不用编写项目的名称 request.getRequestDispatcher("/WEB-INF/pages/success.jsp").forward(request, response); return; } ~~~ ## 重定向 ~~~ @RequestMapping(path = "/ok") public void testResponse(HttpServletRequest request, HttpServletResponse response) throws Exception { //重定向是两次两次请求,所以无法重定向到WEB-INF目录下 response.sendRedirect(request.getContextPath()+"/index.jsp"); return; } ~~~ ## 直接输出 ~~~ @RequestMapping(path = "/ok") public void testResponse(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); response.getWriter().print("hello"); return; } ~~~