0

I have a jsp with a file chooser. I need to take the 'src' of the image to a servlet.How to do this.

<img id="imgEventImage" src="img/Addmovie/ET000242281bb9.jpg" alt="your image"> <div class="ratingBox"> <div class="Add_TrailerMusic"> <div id="upFileImg" class="upld btn-imageUpload" style="margin-left: 28px;"> <span>Add Poster</span> <input id="selectfileImg" name="posterPath" class="uploadImg" style="color: transparent;"type="file"> </div>

3
  • 2
    More input. Show jsp and explain more. Commented Dec 25, 2015 at 18:56
  • @Jan I want to get the image src to a servlet. Commented Dec 25, 2015 at 19:03
  • 1
    You will not get image src - you'll receive image data. search for "upload images from jsp" and you'll find help i think. Commented Dec 25, 2015 at 19:15

1 Answer 1

1

As far as I understand you want to pass parameter to the Servlet from the JSP by using JavaScript...

If so, then it may help.

Make a hidden field inside the form, for example:

<form name="formName" method="POST"> <!-- other fields --> <input type="hidden" name="hiddenFieldName" id="hiddenFieldId" value=""/> <input type="button" name="submitTheFormBtn" onclick="submitTheForm()"/> </form> 

Then submit the form to the server via JavaScript:

<script> function submitTheForm() { var imgSrcParam = document.getElementById("imgEventImage").src; document.getElementById("someFieldId").value = imgSrcParam; document.forms[formName].submit(); /*or give an id to the form you want to submit, then use document.getElementById("formId").submit()*/ } </script> 

In the Servlet you can get this parameter:

String imgSrcParam = request.getParameter("hiddenFieldName"); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.