通过从jsp向servlet发送登录ID将个人资料图片上传到数据库

时间:2019-01-01 12:48:21

标签: java jsp servlets

我从一个servlet获得登录对象,现在我想从我的jsp发送该登录对象或它的ID到另一个servlet,以便在上传个人资料图片时将图像路径上传到数据库。但这不起作用。

这是我的jsp:

<form action="us" method="post" enctype="multipart/form-data">
        <input type="file" class="text-center center-block file-upload" name="photoUpload">
            <input type="submit" name="photoUploadsubmit" id="photoUploadsubmit" tabindex="4"
                    value="Yukle">
            ${login.id}
            <%Login login2 = (Login)request.getAttribute("login");%>

            <%Long idd = login2.getId();%>
            <%String iddd = idd.toString();%>
            <input type="hidden" name="myObjectId" value="<%=iddd%>" />

这是我的另一个servlet的一部分:

  String idd = request.getParameter("myObjectId");
            Long id = Long.parseLong(idd);

            boolean isUploadToDB = loginService.addProfPicPath(filePath,id);
            if (isUploadToDB){
            request.setAttribute("imagePath2",UPLOAD_DIRECTORY + File.separator + newFileName);
            request.setAttribute("imagePath",filePath);
            request.setAttribute("message","Upload has been done successfully");}`

我该如何解决?

0 个答案:

没有答案