2015-06-25 8 views
0

У меня есть форма в jsp. Мои поля ввода также «обязательны», но когда я отправляю форму, она не блокирует отправку, если необходимые поля пустые. Я не понимаю, пожалуйста, помогите спасибо advance.Here мой JSP форма:Проверка формы в jsp перед отправкой

<form id="addterminal" name="catForm" action="actions/Terminal.jsp" method="post" enctype="multipart/form-data"> 
     <fieldset> 
     <label>Add Terminal</label> 
     <% String action = request.getParameter("action"); 
     if(action == null) 
     { 

     } 
     else if(action.equals("add_success")) 
     { 
      %> 
      <div class="alert success">Terminal added Successfully...</div> 
       <% 
     } 

     else if(action.equals("add_failure")) 
     { 
      %> 

      <div class="alert failure">Terminals not added,File Format is incorrect...</div> 
      <% 
     } 
     %> 
     <section> 
      <label for="input">Terminal ID</label> 
      <div> 
      <input type="text" id="input" name="tid" required> 
      </div> 
     </section> 
     <section> 
      <label for="input">Merchant Name</label> 
      <div> 
      <input type="text" id="input" name="merchName" required> 
      </div> 
     </section> 

     <section> 
      <label for="file_upload">Upload Bulk Terminals File<br> 
      <span>Format of the File should be .csv</span></label> 
      <div> 
      <input type="file" id="file_upload" name="termbulkfile"> 
      </div> 
     </section> 

     <section> 
      <div> 
     <!--  <button onclick="javascript:document.catForm.reset()">Reset</button> 
     -->  <button onclick="javascript:document.catForm.submit()">Submit</button> 

      </div> 
     </section> 
     </fieldset> 
    </form> 
+0

http://stackoverflow.com/qu estions/18849200/форма-подтверждение-в-JSP-использованием JavaScript- – Karthigeyan

ответ

1

Вы можете использовать Java Script для этого

<script> 
function validation() { 
    var x = document.forms["myform"]["username"].value; 
    if (x == null || x == "") { 
     alert("username cannot be empty..!!"); 
     return false; 
    } 
</script> 

Создайте такую ​​форму:

<form name="myform" action="**wherever you want to redirect**" onsubmit="return validation()"> 
    <input type="text" name="username"> 
    <input type="submit"> 
</form> 
0

Попробуйте:

if(action.length!=0) 
{ 
... 
} 
Смежные вопросы