springmvc,通过后台跳转到页面后,页面里面请求的图片资源路径根本不对

紫枫叶520 紫枫叶520 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有2个内容一模一样的页面,就是页面路径不一样。一个是在page文件夹,一个直接放在webRoot下。


webRoot下的页面
<body>
页面目录:WebContent下<br/>
本次跳转使用方法${method }<br/>
picture:<img src="image/a.jpg" alt="picture" />
</body>
</html>

page下的页面
<body>
页面目录:WebContent/page下<br/>
本次跳转使用方法${method }<br/>
picture:<img src="../image/a.jpg" alt="picture" />
</body>


我在后台,用注解的方式,控制请求转发到的页面,有2个方法
package com.sudy.controller.annotation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

@Controller
public class AnnotationController extends MultiActionController{

@RequestMapping(value="/method1",method=RequestMethod.GET)
public ModelAndView method1(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {

return new ModelAndView("/page/welcome","method","method1");
}

@RequestMapping(value="/test/method2",method=RequestMethod.GET)
public ModelAndView method2(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {

return new ModelAndView("/welcome","method","method2");
}
}


method1通过http://localhost:8080/springMvc1/method1跳转到page/welcome.jsp
图片路径根本不对,少了springMvc1


method2通过http://localhost:8080/springMvc1/test/method2跳转到welcome.jsp
图片路径也不对,多了个test


我就搞晕了,这设置请求的路径,以及设置返回路径,怎么影响了页面资源的路径,求大神点拨一下
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
紫枫叶520
Web 开发 81,107 成员 341,720 内容