使用@RequestMapping时,请求的源在Spring MVC中不可用

使用@RequestMapping时,请求的源在Spring MVC中不可用,spring,spring-mvc,Spring,Spring Mvc,在SpringMVC中,当使用@RequstMapping时,我在加载.jsp页面时遇到问题。handler方法会响应,但是.jsp页面无法加载,因为我不知道为什么ModelAndView会在字符串中添加表示URL路径的内容。以下是@Controller类中的代码: @RequestMapping(value="/sent/{phoneNumber}", method=RequestMethod.GET) public ModelAndView showSentMessagesToSelecte

在SpringMVC中,当使用
@RequstMapping
时,我在加载
.jsp
页面时遇到问题。handler方法会响应,但是
.jsp
页面无法加载,因为我不知道为什么
ModelAndView
会在字符串中添加表示URL路径的内容。以下是
@Controller
类中的代码:

@RequestMapping(value="/sent/{phoneNumber}", method=RequestMethod.GET)
public ModelAndView showSentMessagesToSelectedPhoneNumber(@PathVariable int phoneNumber,HttpSession session)
{
    ModelAndView modelAndView = new ModelAndView("sentMessagesToPhoneNumber");
            ...
            return modelAndView;
     }
以下是我在
.jsp中看到的内容:

<a href="${pageContext.request.contextPath}/sent/${reciever.getPhoneNumber()}.html">${reciever.getContactName()}</a>

然后,当我点击页面时,浏览器会告诉我:
HTTP Status 404-/homography/sent/WEB-INF/pages/sentMessagesToPhoneNumber.jsp
。 我可以得出结论,
@RequestMapping
中的
/sent
被添加到路径中。
有人能告诉我问题出在哪里吗?

看起来您已经在配置文件中定义了一个
视图解析器。差不多

<bean id="jspViewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"
              value="someViewClass"/>
    <property name="prefix" value="/WEB-INF/pages/"/>
    <property name="suffix" value=".jsp"/>
</bean>


当您在控制器中用名称构造一个
ModelAndView
时,您将被引导到一个带有在bean和名称中定义的前缀和后缀的jsp页面。您得到404可能是因为您在
/WEB-INF/pages/
目录中没有
sentMessagesToPhoneNumber.jsp

以下是我在app-context.xml文件中的内容:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="mk.ukim.finki.mp.homework"></context:component-scan>

    <mvc:resources mapping="/js/**" location="/js/" />

    <import resource="security-context.xml"/>


你能发布你的servlet-config.xml吗?servlet-config.xml在哪里?我只有我创建的app-config.xml。这是一样的,你能发布它吗?我发布了我的app-context.xml文件!我有所有这些,但问题不是我没有在“/WEB-INF/pages/”中
sentMessagesToPhoneNumber.jsp
。问题是,当我单击链接时,不知道是什么在“ModelAndView”对象搜索资源的路径中添加了“/sent”。我不确定确切的问题,但我遇到了。我想这可能会有帮助。