Android端代码
AsyncHttpClient client = new AsyncHttpClient();
//URLEncoder.encode(category, "utf-8");
RequestParams params = new RequestParams();
if(path1!=null){
file1=new File(path1);
}
if(path2!=null){
file2=new File(path2);
}
params.put("shopname", proname);
params.put("description", description);
params.put("price", proprice);
params.put("userphone",usernum);
params.put("category", category);
client.post(url, params, new AsyncHttpResponseHandler(){
@Override
public void onSuccess(String content) {
// TODO Auto-generated method stub
super.onSuccess(content);
if(content.equals("发布成功")){
Toast.makeText(homepage.this, content, 0).show();
name.setText("");
price.setText("");
number.setText("");
intro.setText("");
}else{Toast.makeText(homepage.this, "发布失败", 0).show();}
}
});
服务器端代码:
if(ServletFileUpload.isMultipartContent(request)){
try{
ServletFileUpload upload = new ServletFileUpload(
new DiskFileItemFactory());
List<FileItem> items = upload.parseRequest(request); // 解析请求
int size = items == null ? 0 : items.size();
for (int i = 0; i < size; i++) {
FileItem item = (FileItem) items.get(i); // 获取方法消息体中的每一段内容。
if (item.isFormField()) {// 如果是普通表单项目
if (item.getFieldName().equals("shopname")) {
shop.setShopname(new String(item.getString().getBytes("ISO8859-1"), "UTF-8"));
} else if (item.getFieldName().equals("description")) {
shop.setDescription(new String(item.getString().getBytes("ISO8859-1"), "UTF-8"));
} else if (item.getFieldName().equals("price")) {
shop.setPrice((df.format(Double.valueOf(item.getString()))));
} else if (item.getFieldName().equals("userphone")) {
shop.setUserphone(item.getString());
} else if (item.getFieldName().equals("category")) {
shop.setCategory(new String(item.getString().getBytes("ISO8859-1"), "UTF-8"));
a=new String(item.getString().getBytes("ISO8859-1"), "UTF-8");
}/*else if (item.getFieldName().equals("picture")) {
shop.setPicture(new String(item.getString().getBytes("ISO8859-1"), "UTF-8"));
}else if(item.getFieldName().equals("picture1")){
shop.setPicture1(new String(item.getString().getBytes("ISO8859-1"), "UTF-8"));
}*/else if(item.getFieldName().equals("userid")){
shop.setUserid(Integer.parseInt(new String(item.getString().getBytes())));
}
为啥我用jsp提交中文不乱码,Android提交乱码呢,我用了android-async-http-1.4.4.jar包,post方式提交数据到服务器的,求解决,大神快来吧,我才接触Android,谢谢啦