0

I write the uploaded image into specified path of the system using android.

                MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

                reqEntity.addPart("file", bab);
                reqEntity.addPart("filename",new StringBody("result" + ".jpg"));
                Log.d("usernamenew",username);
                Log.d("passwordnew",password);


                ***reqEntity.addPart("username1",new StringBody(username));
                reqEntity.addPart("password1",new StringBody(password));***

                postRequest.setEntity(reqEntity);

In above code how can i get the value of username and password at the servlet file. My URL is http://192.168.1.201:8080/HttpGetServlet/ImageUploadServlet.

I try to get those values using request.getParameter("username") but it doesn't work.

My servlet code

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    System.out.println("Welcome in Image Uplaod");

    try
    {
        File uploadFile = null;
        String filename = null;
        String filepath_str = "D:/myupload";


        System.out.println("Image Upload from Mobile Device!");

        //Checking Multipart content or not
        isMultipart = ServletFileUpload.isMultipartContent(request);

        if (isMultipart) 
        {
            DiskFileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            File uploadDir = new File(filepath_str);
            if (!uploadDir.exists()) {
                uploadDir.mkdir();
            }

            List formItems;
            try {
                formItems = upload.parseRequest(new ServletRequestContext(request));
                Iterator iter = formItems.iterator();
                 int num=1;
                // iterates over form's fields
                while (iter.hasNext()) {
                    FileItem item = (FileItem) iter.next();
                    // processes only fields that are not form fields
                    if (!item.isFormField()) {
                       String fileName = new File(item.getName()).getName();
                        String filePath = filepath_str + File.separator + fileName;
                        File storeFile = new File(filePath);
                        item.write(storeFile);


**
System.out.println("username is"+request.getParameter("username"));
                            System.out.println("password is"+request.getParameter("password"));
**

                           // connection=DButils.getConnection();
                         //preparedstmt=connection.prepareStatement("update test set photo=? where)


                        }
                    }
                }

In the above code the username and password print as null.

Am i do anything wrong in my code? Please help to access that values...

Asha
  • 750
  • 1
  • 6
  • 22

0 Answers0