web.xml中:
<!--用户put提交参数--><filter><filter-name>HttpMethodFilter</filter-name><filter-class>org.sPRingframework.web.filter.HttpPutFormContentFilter</filter-class></filter><filter-mapping><filter-name>HttpMethodFilter</filter-name><servlet-name>springmvc</servlet-name></filter-mapping>
<servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/conf/*.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
Controller中:
@RequestMapping(value="/{userId}",method = RequestMethod.PUT)
测试的main方法中:
String putStr="http://192.168.1.8:8080/xxx/users/36";try{
HttpPut method=newHttpPut(putStr);
method.setHeader("serverType", "0");
List<NameValuePair> params =newArrayList<NameValuePair>();
params.add(newBasicNameValuePair("orgId", "10"));
params.add(newBasicNameValuePair("userName", "bbbddd_001"));
params.add(newBasicNameValuePair("email", "liwy@xxx.cn"));
params.add(newBasicNameValuePair("phoneNo", "111222"));
method.setEntity(newUrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse response=client.execute(method);
HttpEntity entity=response.getEntity();
String result= EntityUtils.toString(entity, "UTF-8");
System.out.println(result);
}catch(IOException e) {
e.printStackTrace();
}
客户端进行http请求时用到的jar
ezmorph-1.0.6.jar
fluent-hc-4.5.1.jar
httpclient-4.5.1.jar
httpclient-cache-4.5.1.jar
httpclient-win-4.5.1.jar
httpcore-4.4.3.jar
httpmime-4.5.1.jar
jna-4.1.0.jar
jna-platform-4.1.0.jar