spring mvc中请求转发遇到的问题

2019-03-07 16:45:49

已经在spring mvc配置文件中 配置了视图解析器

“forward:xxx”中还是要写全路径才可以访问到
“forward:success”出错

No mapping found for HTTP request with URI [/spring_mvc2/success] in DispatcherServlet with name 'springmvc'

“forward:/WEB-INF/jsp/success.jsp” 正常

springmvc.xml中的配置

  1. <!-- 配置视图解析器 查找返回页面的路径-->
  2. <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  3. <property name="prefix" value="/WEB-INF/jsp/"/>
  4. <property name="suffix" value=".jsp"/>
  5. </bean>

Controller中的代码

  1. @Controller
  2. public class ForwardController {
  3. @RequestMapping("forward")
  4. public String makeForward(Model model,HttpServletRequest request){
  5. model.addAttribute("modelData","model data");
  6. model.addAttribute("requestData","request data");
  7. //请求转发
  8. //警告: No mapping found for HTTP request with URI [/spring_mvc2/success] in DispatcherServlet with name 'springmvc'
  9. //访问路径变为了 /spring_mvc2/success
  10. //return "forward:success"; 出错
  11. return "forward:/WEB-INF/jsp/success.jsp";
  12. }
  13. }

0
1
0

添加评论

正在回复:
取消
11
0
1
0