web端、android端的文件上传
1、web端的文件上传。
这里是利用了第三方的jar包。这里所需要的jar包我已经上传到本博客的资源里了,以下是连接
http://download.csdn.net/detail/caihongshijie6/6239041
代码如下:
1)login.jsp
public boolean uploadFile(String path , String username , String password , String filename) throws Exception{System.out.println("。。。。。自己写的android短的上传文件.......");org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();PostMethod postMethod = new PostMethod(path); Part[] parts = new Part[]{new StringPart("username",username),new StringPart("password",password),new FilePart("file",new File(filename))};MultipartRequestEntity entity = new MultipartRequestEntity(parts, postMethod.getParams());postMethod.setRequestEntity(entity);int responseCode = httpClient.executeMethod(postMethod);if(responseCode == 200){return true;}return false;}