如何消除这个错误 "The request sent by the client was syntactically incorrect ()."
how to remove this error "The request sent by the client was syntactically incorrect ()."
我正在尝试使用这个 link 使网络服务
http://www.programming-free.com/2014/03/spring-mvc-40-restful-web-service-json.html
我遵循所有步骤,因为我需要静态数据,所以我不想连接数据库。但是我收到错误
我按照步骤
1)新建->动态网络项目
2 ) 添加 url
中给出的所有库
commons-logging-1.1.1.jar
jackson-annotations-2.0.0.jar
jackson-core-2.0.0.jar
jackson-databind-2.0.0.jar
jstl-1.2.jar
mysql-connector-java-3.1.12.jar
spring-aop-4.0.0.RELEASE.jar
spring-aspects-4.0.0.RELEASE.jar
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
spring-framework-bom-4.0.0.RELEASE.jar
spring-web-4.0.0.RELEASE.jar
spring-webmvc-4.0.0.RELEASE.jar
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>SpringServiceJsonSample</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
休息-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<context:component-scan base-package="com.programmingfree.springservice.controller" />
<mvc:annotation-driven />
</beans>
controller.js
package com.programmingfree.springservice.controller;
import java.util.HashMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/service/user/")
public class SpringServiceController {
HashMap<String, String> userService=new HashMap<String, String>();
@RequestMapping(value = "/test", method = RequestMethod.GET,headers="Accept=application/json")
public HashMap getUser(@PathVariable int id) {
userService.put("name", "hello");
return userService;
}
}
当我点击服务器时
http://localhost:8080/dddddd/service/user/test
显示 The request sent by client was syntactically incorrect ().
您的 mpaping 需要一个 PathVariable id,但您的映射模式没有定义它
将其添加到请求映射或将其从参数中删除,映射就会成功。以下是移除 PathVariable 的示例
@RequestMapping(value = "/test", method = equestMethod.GET,headers="Accept=application/json")
public HashMap getUser() {
}
我正在尝试使用这个 link 使网络服务 http://www.programming-free.com/2014/03/spring-mvc-40-restful-web-service-json.html 我遵循所有步骤,因为我需要静态数据,所以我不想连接数据库。但是我收到错误
我按照步骤
1)新建->动态网络项目
2 ) 添加 url
中给出的所有库
commons-logging-1.1.1.jar
jackson-annotations-2.0.0.jar jackson-core-2.0.0.jar jackson-databind-2.0.0.jar jstl-1.2.jar mysql-connector-java-3.1.12.jar spring-aop-4.0.0.RELEASE.jar spring-aspects-4.0.0.RELEASE.jar spring-beans-4.0.0.RELEASE.jar spring-context-4.0.0.RELEASE.jar spring-core-4.0.0.RELEASE.jar spring-expression-4.0.0.RELEASE.jar spring-framework-bom-4.0.0.RELEASE.jar spring-web-4.0.0.RELEASE.jar spring-webmvc-4.0.0.RELEASE.jar
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>SpringServiceJsonSample</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
休息-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<context:component-scan base-package="com.programmingfree.springservice.controller" />
<mvc:annotation-driven />
</beans>
controller.js
package com.programmingfree.springservice.controller;
import java.util.HashMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/service/user/")
public class SpringServiceController {
HashMap<String, String> userService=new HashMap<String, String>();
@RequestMapping(value = "/test", method = RequestMethod.GET,headers="Accept=application/json")
public HashMap getUser(@PathVariable int id) {
userService.put("name", "hello");
return userService;
}
}
当我点击服务器时 http://localhost:8080/dddddd/service/user/test 显示 The request sent by client was syntactically incorrect ().
您的 mpaping 需要一个 PathVariable id,但您的映射模式没有定义它
将其添加到请求映射或将其从参数中删除,映射就会成功。以下是移除 PathVariable 的示例
@RequestMapping(value = "/test", method = equestMethod.GET,headers="Accept=application/json")
public HashMap getUser() {
}