public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    String portalId = request.getParameter("portalId");
    if (portalId != null) {
      long id = Long.parseLong(portalId);
      ProfilePerson person = service.findProfilePersonByPortalId(id);

      byte[] images = null;

      if (person.getRegisterType() == ProfilePerson.REAL) {
        images = service.findRealProfilePersonByProfilePersonId(person.getId()).getImage();
      } else if (person.getRegisterType() == ProfilePerson.LEGAL) {
        images = service.findLegalProfilePersonByProfilePersonId(person.getId()).getImage();
      }
      if (images != null) {

        ServletOutputStream ouputStream = null;
        BufferedInputStream inputStream = null;
        response.setContentType("application/download");
        ouputStream = response.getOutputStream();

        ByteArrayInputStream bais = new ByteArrayInputStream(images);
        inputStream = new BufferedInputStream(bais);

        if (inputStream != null) {
          FileCopyUtils.copy(inputStream, ouputStream);
        }
      }
    }

    return null;
  }
  public String doSave() {

    try {

      if (StringUtils.isEmpty(membershipNumber)) {
        ErrorReportingUtils.getInstance().reportErrors("membership-number-is-missing");
        return "";
      }
      if (selectedUnitOrLib instanceof LibraryUnit
          && selectedRequestType == UserManagementDataMap.Request_type.Scholar.getValue()) {
        ErrorReportingUtils.getInstance().reportErrors("select-valid-unit-library");
        return "";
      }

      if (selectedUnitOrLib instanceof OrganizationUnit
          && selectedRequestType != UserManagementDataMap.Request_type.Scholar.getValue()) {
        ErrorReportingUtils.getInstance().reportErrors("select-valid-unit-library");
        return "";
      }

      if (this.realPerson.getProfile() == null) this.realPerson.setProfile(new ProfilePerson());

      ProfilePerson profile = this.realPerson.getProfile();
      profile.setNationality(getNationality());
      profile.setTitle(this.realPerson.getFirstName() + " " + this.realPerson.getLastName());
      profile.setMembershipNo(this.membershipNumber);

      profile.setUserType(ProfilePerson.BOTH);
      profile.setRegisterType(Byte.valueOf(JsfUtils.getFromPageFlow("registerType").toString()));
      profile.setUserName(this.userName);
      profile.setPassword(WebApplication.getInstance().encodePassword(this.password));
      profile.setEmail(this.email);
      this.realPerson.setUniqeName(this.realPerson.createPersonIdentifierKey());

      if (this.selectedRequestType == UserManagementDataMap.Request_type.SafeKeeping.getValue()) {
        service.saveRealLoanProfileRequest(this.realPerson, this.selectedUnitOrLib);
      } else if (this.selectedRequestType
          == UserManagementDataMap.Request_type.Exchange.getValue()) {
        service.saveRealExchangeProfileRequest(this.realPerson, this.selectedUnitOrLib);
      } else if (this.selectedRequestType
          == UserManagementDataMap.Request_type.Scholar.getValue()) {
        service.saveRealProberProfileRequest(this.realPerson, this.selectedUnitOrLib);
      }

      this.realPerson = service.findRealProfilePersonByProfilePersonId(profile.getId());

      NliMailDefinitionServiceProxy.getInstance()
          .sendMessage(
              this.email,
              JsfUtils.getStringFromBundle("userNamePassEmailSubject"),
              "body",
              Constants.UTF8);

      Map map = RequestContext.getCurrentInstance().getPageFlowScope();
      map.put("realPerson", this.realPerson);
      map.put("selectedUnit", this.selectedUnitOrLib);
      map.put("requestType", this.selectedRequestType);

    } catch (DuplicateMembershipNoException exp) {
      ErrorReportingUtils.getInstance()
          .reportErrors(JsfUtils.getStringFromBundle("duplicateMembershipNoException"));
      return "";
    } catch (DuplicateMemberException e) {
      ErrorReportingUtils.getInstance()
          .reportErrors(JsfUtils.getStringFromBundle("duplicateMemberException"));
      return "";
    } catch (DuplicateNationalCodeException e) {
      ErrorReportingUtils.getInstance()
          .reportErrors(JsfUtils.getStringFromBundle("duplicateNationalCodeException"));
      return "";
    } catch (DuplicateUserNameException e) {
      ErrorReportingUtils.getInstance()
          .reportErrors(JsfUtils.getStringFromBundle("duplicateUsernameException"));
      return "";
    } catch (DuplicateLoanProfileException exp) {

      return processException(exp, 0);

    } catch (DuplicateExchangeProfileException exp) {

      return processException(exp, 1);

    } catch (DuplicateProberProfileException exp) {

      return processException(exp, 2);

    } catch (Exception exp) {
      exp.printStackTrace();

      return "";
    } finally {

    }

    return goBackList();
  }