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 = new HttpPut(putStr); method.setHeader("serverType", "0"); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("orgId", "10")); params.add(new BasicNameValuePair("userName", "bbbddd_001")); params.add(new BasicNameValuePair("email", "liwy@xxx.cn")); params.add(new BasicNameValuePair("phoneNo", "111222")); method.setEntity(new UrlEncodedFormEntity(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.jarfluent-hc-4.5.1.jarhttpclient-4.5.1.jarhttpclient-cache-4.5.1.jarhttpclient-win-4.5.1.jarhttpcore-4.4.3.jarhttpmime-4.5.1.jarjna-4.1.0.jarjna-platform-4.1.0.jar
新闻热点
疑难解答