404 - 请求的资源不可用.(弹簧-mvc) [英] 404 -The requested resource is not available. (Spring-mvc)

查看:70
本文介绍了404 - 请求的资源不可用.(弹簧-mvc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Spring MVC 视图解析器不是很熟悉.我正在尝试从我的控制器返回一个 JSP.我的控制器方法正在正确执行,但是在返回视图时,我收到 404 -请求的资源不可用 错误.

I am not very familiar with Spring MVC view resolver.I am trying to return a JSP from my controller. My Controller method is getting executed properly but when returning view, i am getting 404 -The requested resource is not available error.

这是我的 servlet-context.xml 文件中的条目

this is entry in my servlet-context.xml file

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <beans:property name="prefix" value="/WEB-INF/views/" />
  <beans:property name="suffix" value=".jsp" />
</beans:bean>

就是这样,我已经定义了资源结构

this is how, i have defined resource structure

webapp
  --WEB-INF
      --views
         --shop
           --common
             --cart
                myjsp.jsp

就是这样,我从控制器返回 JSP 视图

This is how, i am returning JSP view from controller

private final static String MYVIEW="shop/common/cart/myjsp";
@RequestMapping(value={"/shop/myMethod.html"},  method = RequestMethod.GET)
     public String myMethod(HttpServletRequest request, Model model){
     return MYVIEW;
 }

这是我的应用程序主页网址

this is my application home page URL

http://localhost:7777/my-shop/shop/

不确定我在哪里做的.

编辑我们正在将 Tiles 与 spring 一起使用,并且已经看到了此附加信息

Edit We are using Tiles with spring and have seen this additional information

<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
  <beans:property name="viewClass">
    <beans:value>org.springframework.web.servlet.view.tiles2.TilesView</beans:value>               
  </beans:property>
</beans:bean>

<beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
  <beans:property name="definitions">
    <beans:list>
      <beans:value>/WEB-INF/tiles/tiles-admin.xml</beans:value>
      <beans:value>/WEB-INF/tiles/tiles-shop.xml</beans:value>
    </beans:list>
  </beans:property>
</beans:bean>

不确定如何添加额外的视图解析器?

Not sure how i can add additional view resolver?

错误

请求的资源(/my-shop/WEB-INF/views/shop/common/cart/myjsp.jsp)不可用.
我记下了一件更奇怪的事情,WEB-INF/views 下的几个 JSP 是可访问的,但是当我将新的 JSP 放置在同一位置时,它不起作用并给出相同的错误.

The requested resource (/my-shop/WEB-INF/views/shop/common/cart/myjsp.jsp) is not available.
I noted down one more strange things, few JSPs under WEB-INF/views are accessible but when I placed new JSP on same location it is not working and giving same error.

推荐答案

我可以帮你抓住一些要点,我发现困难的地方

I can help you to catch some points,where I found the difficulty

  1. 在你的 web.xml 中,在 context-param 下配置 servlet-context.xml 的正确路径
  2. 在 servlet-context.xml 下的 context:component-scan base-package="/youcontrollerclass"/- 检查您是否提供了正确的路径
  3. POM.xml 中的依赖文件

这是我的 servlet-context.xml 的一部分

this is part of my servlet-context.xml

    <context:component-scan base-package="mypath"/>

     <bean id="jspViewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />    

这篇关于404 - 请求的资源不可用.(弹簧-mvc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆