首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在服务器端收到请求后Url被修改

在服务器端收到请求后Url被修改
EN

Stack Overflow用户
提问于 2014-06-26 07:23:08
回答 1查看 148关注 0票数 4

我正在尝试使用Spring框架和Apache Tomcat来开发一个RESTful web服务。我添加了两个控制器类,它们有5-6个端点,运行良好。但是自从昨天我尝试添加另一个端点时,我得到了一个奇怪的错误。

代码语言:javascript
复制
@Controller
@RequestMapping("/test")
public class TextController {

    @RequestMapping(method=RequestMethod.POST)
    public void test() {
        System.out.println("Hello world");
    }
}

当我从浏览器(使用REST客户端)尝试这个URL时,我得到了以下输出:

代码语言:javascript
复制
Hello world

Jun 25, 2014 7:05:55 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ChitChatApp/rest/test/test] in         DispatcherServlet with name 'chitchat-dispatcher'

url将显示附加的额外"/test“。我的其他API仍然工作得很好。仅仅是我添加的新代码就会给出这个错误。

我的web.xml看起来像这样:

代码语言:javascript
复制
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ChitChat Web Service</display-name>

<servlet>
    <servlet-name>chitchat-dispatcher</servlet-name>
    <servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/chitchat-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>chitchat-dispatcher</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

不知道为什么会突然发生这样的事情。希望在这方面能帮上忙。

EN

回答 1

Stack Overflow用户

发布于 2015-04-27 00:55:19

@RequestMapping("/test")上看,url应该是"somprefix/test“,但您将请求发送到URL "/ChitChatApp/rest/test/test",这是错误的吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24420187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档