【发布时间】:2016-04-08 22:06:43
【问题描述】:
我有一个 Angular 客户端;其将数据发布到 java Rest Api。当我尝试发送字符串或整数数据时,没有任何问题。但是当我尝试发送 List 时,它给出了一个类似的错误;enter image description here
StandardWrapperValve[org.netbeans.rest.application.config.ApplicationConfig]:Servlet org.netbeans.rest.application.config.ApplicationConfig 的 Servlet.service() 抛出异常 java.lang.IllegalArgumentException:参数类型不匹配
还有我的 Java Api
@POST @Path("/senddata") @Produces("application/json") public String sendData(List<Data> model) throws Exception { System.out.println("model : " + model);
return "OK";
}
来自 Angularjs 的请求
return $http.post('http://localhost:8080/Project/webresources/json/product/senddata', postData1, { headers: { 'Content-Type': 'application/json' } });
我的字符编码类
@WebFilter("*.xhtml")
public class CharacterEncodingFilter implements Filter {
@Override
public void init(FilterConfig config) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.getCharacterEncoding();
response.getCharacterEncoding();
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
}
谢谢
【问题讨论】: