1

In the servlet I am trying to get the value of the submit button in the form below using

JSP and Servlet are diffirent webmodule

Servlet code:

public static String getValue(String value) {
  return (value != null) ? value.trim() : "";
}

String article_title = 
Utilities.getValue(request.getParameter("txtArticleTitle"));
byte article_image_count  = Utilities.getByteParam(request,"txtFileCount");
out.print("Title is: " + article_title+" ----- ");
out.print("File Count is: " + article_image_count);

JSP form:

<form action="" method="" enctype="multipart/form-data">
<textarea name="txtArticleTitle" rows="3" value="" placeholder=""></textarea>
<input id="filePost" type="file" hidden="true" onchange="setImagePost()">
<button type="button" class="btn btn-sm btn-default pull-right" onclick="submitArticleAE(this.form);"></button>
</form>

JS Code

function submitArticleAE(fn){
//to check input form
    alert("Title is: "+fn.txtArticleTitle.value+" ---- File Count is: "+fn.txtFileCount.value);
    if(checkArticleAE(fn)) submitForm(fn,"POST","/adv/article/upload");
}

https://i.stack.imgur.com/BYjOJ.png

Quang Dao Van
  • 17
  • 1
  • 5
  • Why is the action of the form empty? If you want the form submit against the servlet, you need to define the servlet's url as action. Also take care of the form's method and set it to 'post' as you want to upload files. – ibexit Oct 27 '18 at 12:04
  • i checked valid form in javascript and if it is true i will submit – Quang Dao Van Oct 27 '18 at 12:07
  • Thank you for providing more code. Give us a sec. – ibexit Oct 27 '18 at 12:08

1 Answers1

1

While using enctype="multipart/form-data" you can not directly get parameters by using request.getParameter(name);. While using it, form fields aren't available as parameter of the request, they are included in the stream, so you can not get it the normal way. You can find a way to do this in the docs of using http://commons.apache.org/proper/commons-fileupload//using.html, under the section Processing the uploaded items.

Source:

Sending additional data with multipart

greengreyblue
  • 389
  • 3
  • 12