当前位置: 首页 > news >正文

怎么选择网站开发深圳代理记账公司前十名

怎么选择网站开发,深圳代理记账公司前十名,wordpress建立网盘,wordpress上传本地视频在之前一段的项目中#xff0c;使用Java模仿Http Post方式发送参数以及文件#xff0c;单纯的传递参数或者文件可以使用URLConnection进行相应的处理。 但是项目中涉及到既要传递普通参数#xff0c;也要传递多个文件#xff08;不是单纯的传递XML文件#xff09;。在网上…在之前一段的项目中使用Java模仿Http Post方式发送参数以及文件单纯的传递参数或者文件可以使用URLConnection进行相应的处理。           但是项目中涉及到既要传递普通参数也要传递多个文件不是单纯的传递XML文件。在网上寻找之后发现是使用HttClient来进行响应的操作起初尝试多次依然不能传递参数和传递文件后来发现时因为当使用HttpClient时不能使用request.getParameter()对普通参数进行获取而要在服务器端使用Upload来进行操作。           HttpClient4.2 jar下载 http://download.csdn.net/detail/just_szl/4370574          客户端代码   [java] view plaincopy import java.io.ByteArrayOutputStream;  import java.io.File;  import java.io.IOException;  import java.io.InputStream;  import org.apache.http.HttpEntity;  import org.apache.http.HttpResponse;  import org.apache.http.HttpStatus;  import org.apache.http.ParseException;  import org.apache.http.client.HttpClient;  import org.apache.http.client.methods.HttpPost;  import org.apache.http.entity.mime.MultipartEntity;  import org.apache.http.entity.mime.content.FileBody;  import org.apache.http.impl.client.DefaultHttpClient;  import org.apache.http.util.EntityUtils;    /**  *   * author a hrefmailto:just_szlhotmail.com Geray/a  * version 1.0,2012-6-12   */  public class HttpPostArgumentTest2 {        //file1与file2在同一个文件夹下 filepath是该文件夹指定的路径          public void SubmitPost(String url,String filename1,String filename2, String filepath){                    HttpClient httpclient  new DefaultHttpClient();                    try {                    HttpPost httppost  new HttpPost(url);                            FileBody bin  new FileBody(new File(filepath  File.separator  filename1));                              FileBody bin2  new FileBody(new File(filepath  File.separator  filename2));                            StringBody comment  new StringBody(filename1);                MultipartEntity reqEntity  new MultipartEntity();                            reqEntity.addPart(file1, bin);//file1为请求后台的File upload;属性                   reqEntity.addPart(file2, bin2);//file2为请求后台的File upload;属性               reqEntity.addPart(filename1, comment);//filename1为请求后台的普通参数;属性                 httppost.setEntity(reqEntity);                            HttpResponse response  httpclient.execute(httppost);                                              int statusCode  response.getStatusLine().getStatusCode();                                              if(statusCode  HttpStatus.SC_OK){                                        System.out.println(服务器正常响应.....);                                    HttpEntity resEntity  response.getEntity();                                                      System.out.println(EntityUtils.toString(resEntity));//httpclient自带的工具类读取返回数据                                                                        System.out.println(resEntity.getContent());                       EntityUtils.consume(resEntity);              }                                } catch (ParseException e) {                  // TODO Auto-generated catch block                  e.printStackTrace();              } catch (IOException e) {                  // TODO Auto-generated catch block                  e.printStackTrace();              } finally {                  try {                       httpclient.getConnectionManager().shutdown();                   } catch (Exception ignore) {                                        }              }          }                  /**      * param args      */      public static void main(String[] args) {          // TODO Auto-generated method stub                    HttpPostArgumentTest2 httpPostArgumentTest2  new HttpPostArgumentTest2();                    httpPostArgumentTest2.SubmitPost(http://127.0.0.1:8080/demo/receiveData.do,                  test.xml,test.zip,D://test);      }        }   服务端代码     [java] view plaincopy public void receiveData(HttpServletRequest request, HttpServletResponse response) throws AppException{            PrintWriter out  null;          response.setContentType(text/html;charsetUTF-8);                    Map map  new HashMap();          FileItemFactory factory  new DiskFileItemFactory();          ServletFileUpload upload  new ServletFileUpload(factory);          File directory  null;            ListFileItem items  new ArrayList();          try {              items  upload.parseRequest(request);              // 得到所有的文件              IteratorFileItem it  items.iterator();              while (it.hasNext()) {                  FileItem fItem  (FileItem) it.next();                  String fName  ;                  Object fValue  null;                  if (fItem.isFormField()) { // 普通文本框的值                      fName  fItem.getFieldName();  //                  fValue  fItem.getString();                      fValue  fItem.getString(UTF-8);                      map.put(fName, fValue);                  } else { // 获取上传文件的值                      fName  fItem.getFieldName();                      fValue  fItem.getInputStream();                      map.put(fName, fValue);                      String name  fItem.getName();                      if(name ! null  !(.equals(name))) {                          name  name.substring(name.lastIndexOf(File.separator)  1);                            //                      String stamp  StringUtils.getFormattedCurrDateNumberString();                          String timestamp_Str  TimeUtils.getCurrYearYYYY();                          directory  new File(d://test);                                 directory.mkdirs();                                                    String filePath  (d://test) timestamp_Str File.separator  name;                          map.put(fName  FilePath, filePath);                                                    InputStream is  fItem.getInputStream();                          FileOutputStream fos  new FileOutputStream(filePath);                          byte[] buffer  new byte[1024];                          while (is.read(buffer)  0) {                              fos.write(buffer, 0, buffer.length);                          }                          fos.flush();                          fos.close();                          map.put(fName  FileName, name);                      }                  }              }          } catch (Exception e) {              System.out.println(读取http请求属性值出错!);  //          e.printStackTrace();              logger.error(读取http请求属性值出错);          }                    // 数据处理                                                  try {              out  response.getWriter();              out.print({success:true, msg:接收成功});              out.close();          } catch (IOException e) {              e.printStackTrace();          }          }   http://blog.csdn.net/Just_szl/article/details/7659347
http://www.yutouwan.com/news/343932/

相关文章:

  • 网站页面分析在重庆找做网站的技术人员
  • 做网站找我们如何网络推广自己的产品
  • 建立什么网站可以赚钱合肥的网站建设公司哪家好
  • 广州网站制作十年乐云seo广告平面设计欣赏
  • 福建省建设职业管理中心网站搜索引擎主要包括三个部分
  • 网站设计师培训班安卓应用市场app
  • 泉州网站建设做一个网站的建设流程
  • 杭州市网站seo设计师拥有的设计导航
  • 设计色彩的门户网站模板厦门站长优化工具
  • 婚嫁网站设计网站短片怎么做
  • html网站建设的步骤微信开发公众平台
  • 做菠菜网站多少钱网站建设最基础的是什么
  • 广中路街道网站建设网站开发技巧
  • 快速生成网站程序如何建设招聘网站
  • 邹城建设银行网站it网站建设方案
  • 建德网站超市网站模版
  • 南城区做网站建设网站必须要服务器吗
  • 国外 做励志视频的网站淄博网站建设补贴
  • 郑州的网站建设公司哪家好网站建设 石家庄
  • 深圳市力同科技有限公司长春做网络优化的公司
  • flash网站建设价格wordpress 教学下载
  • 网站后台尺寸一般做多大的建筑导航网站
  • 模仿建设银行网站深圳南山网站建设工作室
  • 企业网站开发的文献综述个人做网站有什么用
  • server2008 做网站网络科技有限公司照片
  • 网站服务器租一个月长春做网站电话
  • 如何上传网站到空间大学生做网站怎么赚钱
  • 承接网站网站建设网站建设图片编辑
  • wordpress网站价钱wordpress页面评论
  • Wordpress网站仿站wordpress化学式编辑插件